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

How to get command column name

6 Answers 204 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ewart
Top achievements
Rank 1
ewart asked on 17 Nov 2008, 08:42 PM


     
private void myGrid_CommandCellClick(object sender, EventArgs e) 
      { 
         GridCommandCellElement gCommand = (sender as GridCommandCellElement); 
 
         if( gCommand.ColumnIndex == 11 ) 
             // code..
      } 
 

Simple question - I have two command buttons and wondered if it's possible to get the unique name from within the event?! can only find the column index number.    gCommand.Name returns ""

Cheers
  Ewart.

6 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 19 Nov 2008, 08:23 PM
Hi ewart,

Thank you for your question. Here is the code you need to use:

MessageBox.Show(gCommand.Value.ToString()); 
 

Do not hesitate to write me back if you have further questions.

All the best,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
ewart
Top achievements
Rank 1
answered on 21 Nov 2008, 06:45 AM
Sorry, thats the value; I wondered if it's possible to get the unique name from within the event? 

cheers
ewart
0
Nick
Telerik team
answered on 21 Nov 2008, 04:28 PM
Hi ewart,

Thank you for your questions.

If you need just row number you can use gCommand.RowIndex.

You may use another cell on the same row to distinguish between click on one row or another:

this.radGridView1.Rows[gCommand.RowIndex].Cells[5].Value 
 
The code above accesses the cell value in the 6th cell on the same row.

Do not hesitate to write me back if you have more questions.

All the best,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
ewart
Top achievements
Rank 1
answered on 21 Nov 2008, 08:20 PM
Huh?  Sorry perhaps my question wasn't clear as we're talking at cross purposes - I shall elaborate.   What I want to know is "How to get the command column name" from within the following event:

private void myGrid_CommandCellClick(object sender, EventArgs e) 
      { 
         GridCommandCellElement gCommand = (sender as GridCommandCellElement); 
 
         if( gCommand.ColumnIndex == 11 ) 
             // code..
      } 
 

Why is because ColumnIndex changes everytime someone re-orders the columns.  Ideally I'd use the command column name, something like e.g.

private void myGrid_CommandCellClick(object sender, EventArgs e) 
      { 
         GridCommandCellElement gCommand = (sender as GridCommandCellElement); 
 
         if( gCommand.ColumnName == "cmdEdit" ) 
             // code..

         if( gCommand.ColumnName == "cmdDelete" ) 
            // code..
      } 
 
I feel a bit sheepish about not being able to find the relevant property in the debug window (and there is basically nothing on "reorder" in the documentation) - but I know it must be there somewhere otherwise you'd have no way of handling re-ordered columns, I just can't figure it out!

cheers
  ewart
0
Nick
Telerik team
answered on 24 Nov 2008, 08:54 AM
Hello ewart,

Thank you for contacting me back.

You can use the column header text:

gCommand.ColumnInfo.HeaderText 

Do not hesitate to contact me back if you have more questions.

Kind regards,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Support@silverbear.com
Top achievements
Rank 1
answered on 03 Dec 2014, 03:48 PM
- He was actually after:gCommand.ColumnInfo.Name
Tags
GridView
Asked by
ewart
Top achievements
Rank 1
Answers by
Nick
Telerik team
ewart
Top achievements
Rank 1
Support@silverbear.com
Top achievements
Rank 1
Share this question
or