This is a migrated thread and some comments may be shown as answers.

How to use RadGrid1_ItemCommand to show data to text box

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Quoc
Top achievements
Rank 1
Quoc asked on 22 Oct 2013, 04:43 PM
I have a grid . I want only when click in edit link buton the info of Item will show on textboxName. But when I click no thing happen.
 I try to add <UpdatedControls> </UpdatedControls> then when i short grid the textbox also refress.

I also try add  RadAjaxPanel1.ResponseScripts.Add(String.Format("$find('{0}').ajaxRequest();", RadAjaxPanel1.ClientID));
when showdata but it does not work

<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
        EnableRoundedCorners="false" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1">
                    </telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"  >
    </telerik:RadAjaxLoadingPanel>
 
  <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
       <telerik:RadTextBox ID="txtName" runat="server">
</telerik:RadTextBox>
.....
      </telerik:RadAjaxPanel>
 
 
<telerik:RadGrid AutoGenerateColumns="False" ID="RadGrid1" AllowFilteringByColumn="True"
        AllowSorting="True" PageSize="15" ShowFooter="True" AllowPaging="True" runat="server" LoadingPanelID="RadAjaxLoadingPanel1"
        OnNeedDataSource="RadGrid1_NeedDataSource" CellSpacing="0" GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound"
        OnItemCommand="RadGrid1_ItemCommand">
        <GroupingSettings CaseSensitive="false"></GroupingSettings>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
        <MasterTableView AutoGenerateColumns="false" AllowFilteringByColumn="True" ShowFooter="True"
            DataKeyNames="Id">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            </ExpandCollapseColumn>
            <Columns>
     <telerik:GridButtonColumn ButtonType="LinkButton" CommandName="_edit" CommandArgument="Id"
                    Text="Edit" UniqueName="Edit">
                </telerik:GridButtonColumn>
 </Columns>
            <EditFormSettings>
                <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn1 column">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>


Code Behind: 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "_edit")
        {
             int id = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"]);
             LoadItem(id); // Show data to textbox
        }
    }

Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 23 Oct 2013, 05:29 AM
Hi ,

I'm not sure about if you want the textbox to be filled during edit mode,if so please try the following code snippet,and add the TextBox to the ajax.

ASPX:
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
    EnableRoundedCorners="false" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="txtName" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
<telerik:RadGrid AutoGenerateColumns="true" ID="RadGrid1" AllowPaging="True" runat="server"
    OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand"
    OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView DataKeyNames="CustomerID">
     . . . . . .
        <Columns>      
            <telerik:GridEditCommandColumn ButtonType="LinkButton">
            </telerik:GridEditCommandColumn>
        </Columns>      
    </MasterTableView>
</telerik:RadGrid>
<br />
<telerik:RadTextBox ID="txtName" runat="server">
</telerik:RadTextBox>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem edit = (GridEditableItem)e.Item;
        String id = edit.GetDataKeyValue("CustomerID").ToString();
        txtName.Text = id;
    }
}

If you want the textbox to be filled on the Button click please try the following code snippet.

ASPX:
<telerik:GridButtonColumn ButtonType="LinkButton" CommandName="_edit" Text="edit"
    UniqueName="Edit">
</telerik:GridButtonColumn>

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "_edit")
    {
        GridDataItem item = (GridDataItem)e.Item;
        string id = item.GetDataKeyValue("CustomerID").ToString();
        txtName.Text = id;
    }
}

Let me know if any concern.

Thanks,
Shinu

Tags
Grid
Asked by
Quoc
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or