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

Setting Grid Button CommandName by Row

2 Answers 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 14 Jan 2009, 06:21 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Jan 2009, 03:55 AM
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.
0
Dennis
Top achievements
Rank 1
answered on 15 Jan 2009, 12:29 PM
Thank you.
Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dennis
Top achievements
Rank 1
Share this question
or