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

radgrid editcommand: accessing columns of selected item

1 Answer 251 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin Jones
Top achievements
Rank 1
Justin Jones asked on 14 Jul 2008, 03:14 PM
Hi there,

I want to modify the functionality of the EditCommand to redirect to another page, passing the key value in the URL.  Something like this...

protected void RadGrid1_EditCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {

            string sPrimaryKey = ??; // Primary key of selected item

            Response.Redirect("CompanyEdit.aspx?Key=" + sPrimaryKey);

            Response.End();

        }

What's the best way to do that?

Thx!
Justin

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jul 2008, 06:16 AM
Hello Justin,

According to my understanding, you can set the Primary Key as the DataKeyName and access it on clicking the Edit button as shown below.

ASPX:
<MasterTableView DataKeyNames="Project_ID"
      <Columns> 
            <telerik:GridBoundColumn DataField="Project_ID" UniqueName="Project_ID" HeaderText="Project_ID"
            </telerik:GridBoundColumn> 
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>             
      </Columns>                 
</MasterTableView> 

CS:
  protected void RadGrid1_EditCommand(object source, GridCommandEventArgs e) 
    { 
        if(e.Item is GridDataItem) 
        { 
            GridDataItem item=(GridDataItem)e.Item; 
            string strtxt = item.GetDataKeyValue("Project_ID").ToString();             
            Response.Redirect("Default.aspx?Key=" + strtxt); 
            Response.End(); 
        } 
    } 

Thanks
Princy.


Tags
Grid
Asked by
Justin Jones
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or