Dynamic CommandNames

3 posts, 0 answers
  1. Jeff
    Jeff avatar
    17 posts
    Member since:
    Sep 2012

    Posted 15 Nov 2012 Link to this post

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Nov 2012 Link to this post

    Hi Jeff,

    Please try the following approach to give CommandName for GridbuttonColumn.

    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();

  3. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 20 Nov 2012 Link to this post

    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.
Back to Top