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

EditCommandColumn command argument?

2 Answers 330 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 30 Mar 2012, 09:14 PM
I'm trying to get a list to populate in an edit form when the user clicks "edit" but the GridEditCommandColumn doesn't have a "CommandArgument" property. What would be the best way to work around that?

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 Mar 2012, 05:32 AM
Hello Kyle,


Please check below code snippet.

<MasterTableView DataKeyNames="ID" >
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn>
                       <ItemTemplate>
                           <asp:Label ID="Label1" Text='<%# Eval("ID") %>' runat="server"></asp:Label>
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.EditCommandName)
       {
           GridEditableItem item = e.Item as GridEditableItem;
           string strkey = item.GetDataKeyValue("ID").ToString();
           string strcolumn1 = item["ID"].Text; // bound column
           string strcolumn2 = (item.FindControl("Lable1") as Label).Text; // find contorl
 
       }
       if (e.CommandName == RadGrid.UpdateCommandName)
       {
           GridEditableItem item = e.Item as GridEditableItem;
           string strkey = item.GetDataKeyValue("ID").ToString();
           string strcolumn1 = item["ID"].Text; // bound column
           string strcolumn2 = (item.FindControl("Lable1") as Label).Text; // find contorl
       }
   }


Thanks,
Jayesh Goyani
0
Shinu
Top achievements
Rank 2
answered on 02 Apr 2012, 06:07 AM
Hello Kyle,

Try the following code in ItemDataBound event to set CommandArgument for EditColumn.
aspx:
<telerik:GridEditCommandColumn ButtonType="LinkButton" UniqueName="EditColumn"></telerik:GridEditCommandColumn>
C#:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
   GridDataItem item = (GridDataItem)e.Item;
   LinkButton link = (LinkButton)item["EditColumn"].Controls[0];
   link.CommandArgument = DataBinder.Eval(e.Item.DataItem, "Id").ToString();
  }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Kyle
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or