Friday, January 09, 2009

Get GridViewRow in button click event in GridView control

When we use template field columns with buttons in gridview, we may need to access the row number to find the datakeys in the button click event. And here is the code how it looks like..

protected void lnkBtnCheckIn_Click(object sender, EventArgs e)
LinkButton lnkButton = sender as LinkButton;
GridViewRow row = lnkButton.Parent.Parent as GridViewRow;
int fleetMovemetId = 0;
int.TryParse(Gridview1.DataKeys[row.RowIndex].Values[1].ToString(), out fleetMovemetId);


No comments: