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

Bindable properties for programmatically created column

2 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikael
Top achievements
Rank 1
Mikael asked on 27 Aug 2008, 11:06 AM
Hi!

I am creating my RadGrid entirely programmatically, no declarations in any ASPX-page.
My question concerns if it somehow is possible to bind properties of a certain column.
For instance, let's save I create a GridButtonColumn:
GridButtonColumn bc = new GridButtonColumn();
... // set up the column
bc.CommandName = DoMagicBindingToField("CommandNameColumn");
In this case, the button for each row in the grid would have a CommandName that comes from the CommandNameColumn-column in the datasource.

Is there anything like DoMagicBindingToField?
In other words, I would like to do something that corresponds to the following declaration in an ASPX-page:
<telerik:GridButtonColumn CommandName="<% eval("CommandNameColumn")">

I believe I can do this with template-columns, but that is not an option for my, I need to use GridButtonColumn.

Many thanks!
/Fredrik

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Aug 2008, 11:28 AM
Hi Fredrik,

One suggestion would be to access the LinkButton from the GridButtonColumn in the ItemDataBound event and set its CommandName to the text of the desired column.

CS:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            LinkButton lnkbtn = (LinkButton)item["ButtonColumnUniqueName"].Controls[0]; 
            lnkbtn.CommandName = item["CommandNameColumn"].Text; 
        } 
   } 
 


Thanks
Princy
0
Mikael
Top achievements
Rank 1
answered on 27 Aug 2008, 12:10 PM
Thanks, that will work!
Tags
Grid
Asked by
Mikael
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mikael
Top achievements
Rank 1
Share this question
or