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

from control in template column to row datakey

1 Answer 29 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Franco Gozzi
Top achievements
Rank 1
Franco Gozzi asked on 18 Jul 2010, 02:50 PM
I post another problem. I would like to retrieve the key value of the row when i click on a control (imageButton) situated in a template column of the row or in the editformtemplate. In the classic aspnet GridView  i used this code:

protected

 

void ImageButtonTest_Click(object sender, ImageClickEventArgs e)

 

{

 

ImageButton imageButton = (ImageButton)sender;

 

 

TableCell tableCell = (TableCell)imageButton.Parent;

 

 

GridViewRow row = (GridViewRow)tableCell.Parent;

 

 

string id = GridViewTest.DataKeys[row.RowIndex].Values[0].ToString();

 

...
}

Any idea? Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Jul 2010, 05:53 AM
Hello Franco,

You can try the following code snippet to access the DataKeyValue of the row on a ButtonClick of ImageButton which is situated in EditItemTemplate.

C#:
protected void ImageButtonTest_Click(object sender, ImageClickEventArgs e)
   {
       ImageButton imageButton = (ImageButton)sender;
       GridEditFormItem editItem = (GridEditFormItem)imageButton.NamingContainer;
       string id = editItem.GetDataKeyValue("ColumnUniqueName").ToString(); 
   }

Thanks,
Princy.
Tags
Grid
Asked by
Franco Gozzi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or