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

[Solved] Column CommandName and CommandArgument

1 Answer 983 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 23 Jul 2009, 09:46 AM
When I do a radgrid (q2, 2009) databind on the client side, I want to set the column command argument (GridButtonColumn in this case). Alternatively, I'd like to set the command argument of the button inside this column.

I'd also like to set the command argument and name in the server side radgrid ItemDataBound event handler.

I have found no documentation or examples on how to do this. Any ideas?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Jul 2009, 11:35 AM
Hello Alex,

If i understand you correctly, you want to set the CommandName and Command Argument for a GridButtonColumn.  Declaratively, you can set the CommandName and CommandArgument of the GridButtonColumn in the aspx as shown below:
aspx:
 <telerik:GridButtonColumn UniqueName="ButtonColumn" Text="ButtonText"  
 CommandName="CustomCommand" CommandArgument="CustomCommandArg"
 </telerik:GridButtonColumn> 

Also to set the CommandName and CommandArgument of the GridButtonColumn from code behind, you can try either of the following approaches:
c#:
 
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
       if (e.Item is GridDataItem) // to set the Command Name/Argument conditionally  
        {  
            GridDataItem dataItem = (GridDataItem)e.Item;  
            if (dataItem["BoundColumnUniqueName"].Text == "Text1")  
            {  
                Button btn = (Button)dataItem["ButtonColumn"].Controls[0];  
                btn.CommandArgument = "CustomArg";  
                btn.CommandName = "CustomName";  
            }  
        }  
   }  
 
(OR)
  protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
       foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)//to set the Command/NameArgument generally  
        { 
            if (col.UniqueName == "ButtonColumn"
            { 
                (col as GridButtonColumn).CommandName == "CustomName"
                (col as GridButtonColumn).CommandArgument == "CustomArg"
            } 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or