Setting Grid Button CommandName by Row

3 posts, 1 answers
  1. Dennis
    Dennis avatar
    62 posts
    Member since:
    Oct 2007

    Posted 14 Jan 2009 Link to this post

    Using the Grid, is there a way to change the CommandName on a GridButtonColumn based on values in the row? For example, you might have 10 grid rows that as a user could have different permissions (view only, update, delete) to each row. I would like to have one "Action" column that has the appropriate "View" or "Update" statement in the column based on the permissions the user has to that data on that specific row.

    So, I want assign values to the CommandName and Text of a GridButtonColumn on a row by row basis based on data values in the row.
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Jan 2009 Link to this post

    Hello Dennis,

    Try out the following code to change the CommandName and Text on a GridButtonColumn based on row values:
    cs:
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem dataItem = (GridDataItem)e.Item; 
                string strtxt = dataItem["Action"].Text; 
                Button btn = (Button)dataItem["ButtonColumnUniqueName"].Controls[0]; 
                if (strtxt == "View") 
                { 
                    btn.Text = "View"
                    btn.CommandName = "View"
                } 
                else if (strtxt == "Update") 
                { 
                    btn.Text = "Update"
                    btn.CommandName = "Update"
                } 
            } 
         } 
     
    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dennis
    Dennis avatar
    62 posts
    Member since:
    Oct 2007

    Posted 15 Jan 2009 Link to this post

    Thank you.
Back to Top