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

Dynamic CommandNames

2 Answers 57 Views
Button
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 15 Nov 2012, 06:42 PM
Hello, everyone.

I have a question regarding the timing and functionality of a RadButton inside a GridButtonColumn.

I have a RadGrid that's getting its data from SQL.  In the GridButtonColumn is a PushButton that has its button text set from a field in the database.  Since these buttons will do different things based on their text, I'd like to know if it's possible to dynamically assign the CommandName property.  I've noticed that I can't use things like CommandName='<%# DataBinder.Eval(Container, "DataItem.buttonCmd") %>' like I can with GridBoundColumns.  Is there another way I can do this?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Nov 2012, 05:37 AM
Hi Jeff,

Please try the following approach to give CommandName for GridbuttonColumn.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem ditem = (GridDataItem)e.Item;
        Button btn = (Button)ditem["UniqueName"].Controls[0];
        btn.CommandName = (string)DataBinder.Eval(e.Item.DataItem, "buttonCmd").ToString();
    }
}

Thanks,
Shinu.
0
Kevin
Top achievements
Rank 2
answered on 20 Nov 2012, 09:46 PM
Hey Jeff,

Another approach would be to use a GridTemplateColumn and add your RadButton's in the ItemTemplate. This way you can use the binding syntax to change the CommandName property.

I hope that helps.
Tags
Button
Asked by
Jeff
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 2
Share this question
or