Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Respected Fellows,
I have showed my data on a form in gridview. Now i want that when i click on a cell on a grid view it should get the Row Id of that selected row. Please tell me how can i do that?.
Posted
Updated 30-Apr-10 22:36pm
v2

Try this code

protected void gridcommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
GridView gv = (GridView)(e.CommandSource);
string s = gv.DataKeys[row.RowIndex][0].ToString();
}
 
Share this answer
 
See this post.
 
Share this answer
 
Considering that in the first column of your datagridview is the row id then you can use below code to determine what is the current id of the selected row.


private void datagridname_CellClick(object sender, DataGridViewCellEventArgs e)

string sRowID = datagridname.Rows[e.RowIndex].Cells[0].Value.ToString()



Thanks,
Chaegie
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900