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

CommandName is empty if the column if created from code

1 Answer 288 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 13 Nov 2008, 03:23 PM
Hi

Im trying to create a Grid entirely from code. But I am experiencing som problems when I add a "GridButtonColumn" and specify a CommandName. In "RadGrid_ItemCommand" when I check the value of e.CommandName I get an empty string.

This I how my column is defined:

Telerik.Web.UI.GridButtonColumn cColumn3 = new Telerik.Web.UI.GridButtonColumn();  
cColumn3.HeaderText = "Header1";  
cColumn3.UniqueName = "column1";  
cColumn3.DataTextField = "name";  
cColumn3.CommandName = "ModifyItem"

If the add the column to my grid the "standard" way like:

<MasterTableView> 
    <Columns> 
       <telerik:GridButtonColumn HeaderText="Header1" UniqueName="column1" CommandName="ModifyItem" DataTextField="name"/>
    </Columns> 
</MasterTableView> 
 

.. then it works fine (e.CommandName = "ModifyItem").

Does anyone know if the is a bug when setting the "CommandName" in code.

Could anyone please provide me with a working example of creating a GridButtonColumn from code with a CommandName that can be checked in the even "ItemCommand".

Thanks In advance

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Nov 2008, 07:37 AM
Hi Martin,

This is the code I tried and it is working fine on my end.

CS:
protected void Page_Load(object sender, EventArgs e)  
    { 
        if (!IsPostBack) 
        { 
            GridButtonColumn btnCol = new GridButtonColumn(); 
            RadGrid1.MasterTableView.Columns.Add(btnCol); 
            btnCol.HeaderText = "Header1"
            btnCol.UniqueName = "column1"
            btnCol.DataTextField = "name"
            btnCol.CommandName = "ModifyItem"
            RadGrid1.MasterTableView.Rebind(); 
        } 
    } 

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