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

button column

1 Answer 682 Views
GridView
This is a migrated thread and some comments may be shown as answers.
yarik
Top achievements
Rank 1
yarik asked on 20 Aug 2007, 07:51 AM
is there a way to set a button Column

in the data grid so i can use it like

---------------------------------
user name |       
----------------------------------
user1       | press to Actived
~~~~~~~~~~~~~~~~~~~~~~~
user2       | press to Actived


.....

1 Answer, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 20 Aug 2007, 01:20 PM
Hi Yarik,

Here is an example of how to add a command column (containing buttons) and set the text of the buttons:
 
protected override void OnLoad(object sender, EventArgs e) 
    radGridView1.CommandCellClick += new CommandCellClickEventHandler(GridCommandCellClick); 
    radGridView1.RowFormatting += new RowFormattingEventHandler(GridRowFormatting); 
 
    // Add command column (containing button) 
    GridViewCommandColumn commandColumn = new GridViewCommandColumn(); 
    commandColumn.UniqueName = "Command"
    commandColumn.HeaderText = "Command"
    commandColumn.Width = 100; 
    radGridView1.MasterGridViewTemplate.Columns.Add(commandColumn); 
 
private void GridRowFormatting(object sender, RowFormattingEventArgs e) 
    GridViewRowInfo gvri = e.RowElement.RowInfo; 
             
    RadButtonElement rbe = gvri.Cells["Command"] != null && gvri.Cells["Command"].CellElement != null ? 
                     gvri.Cells["Command"].CellElement.Children[0] as RadButtonElement : null
 
    if (gvri.Cells["Status"].Value is bool && rbe != null
        rbe.Text = (bool) gvri.Cells["Status"].Value ? "Activate" : "Deactivate"
    else 
        rbe.Text = "Unknown status"
 
 
private void radGridView1_CommandCellClick(object sender, EventArgs e) 
    GridCommandCellElement gcce = sender as GridCommandCellElement; 
 
    if (gcce == null || gcce.Value == null
        return
 
    MessageBox.Show(gcce.Value.ToString()); 
 

You can also take a look at the source code of the RadGridView's Column Types example in our examples. If you have further questions, just write us back and we will do our best to help you.
 

All the best,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
yarik
Top achievements
Rank 1
Answers by
Dwight
Telerik team
Share this question
or