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

RadGrid EditCommand Row click value in session

2 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 03 Sep 2014, 12:46 PM
Hi,

how can i take row click(edit button of row) value on editcommand event in radgrid?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Swapnil
Top achievements
Rank 1
answered on 04 Sep 2014, 11:23 AM
any solution plz.
0
Konstantin Dikov
Telerik team
answered on 08 Sep 2014, 08:22 AM
Hello Swapnil,

I am not sure if I understand exactly your question, but if you want to handle the command initiated by a button with set CommandName property within an item, you could handle the server-side OnItemCommand event of the grid. Additionally, if you need to retrieve a value from the item initiating the command you could use the event arguments for getting that item and cast it to a GridDataItem.

For your convenience, following is a very basic example demonstrating the above scenario:
<asp:Label runat="server" ID="Label1"></asp:Label>
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView AutoGenerateColumns="false">
        <Columns>
            <telerik:GridBoundColumn DataField="ID"></telerik:GridBoundColumn>
            <telerik:GridButtonColumn Text="Edit" CommandName="Edit"></telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    for (int i = 0; i < 3; i++)
    {
        table.Rows.Add(i);
    }
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "Edit")
    {
        GridDataItem item = e.Item as GridDataItem;
        string id = item["ID"].Text;
        Label1.Text = id;
    }
}

If the above does not help for your requirement, please provide more detailed information on what exactly you need to achieve. 


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Swapnil
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or