find datakey name's in gridview event handlers
1)In row databound
if (e.Row.RowType == DataControlRowType.DataRow)
{
int datakey = Convert.ToInt32(dgFixtures.DataKeys[e.Row.RowIndex].Value.ToString());
}
if (e.Row.RowType == DataControlRowType.DataRow && GridTeamOfficials.EditIndex == e.Row.RowIndex)
{
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton deleteLink = (ImageButton)e.Row.Cells[3].Controls[1];
//WebControl deleteLink = (WebControl)e.Row.Cells[3].Controls[0];
deleteLink.Attributes.Add("OnClick", "javascript:return CheckforDelete();");
}
2)Datarowview
DataRowView drv = (DataRowView)e.Row.DataItem;
string Player_Response = drv[""].ToString();
3)in row command
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
int Key = int.Parse(dg.DataKeys[row.RowIndex].Values[1].ToString());
if we r using paging in row command
int rindex = Convert.ToInt32(e.CommandArgument.ToString());
string MemberKey = GridView1.DataKeys[rindex - (GridView1.PageIndex * GridView1.PageSize)].Value.ToString();
4)Row deleting
GridView1.DataKeys[e.RowIndex].Value.ToString());
Boolean FixtureCancel = Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem, "Fixture_Canceled"));
5)Row updating
Convert.ToInt32(GridTeamOfficials.DataKeys[e.RowIndex].Value.ToString());
if (e.Row.RowType == DataControlRowType.DataRow)
{
int datakey = Convert.ToInt32(dgFixtures.DataKeys[e.Row.RowIndex].Value.ToString());
}
if (e.Row.RowType == DataControlRowType.DataRow && GridTeamOfficials.EditIndex == e.Row.RowIndex)
{
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
ImageButton deleteLink = (ImageButton)e.Row.Cells[3].Controls[1];
//WebControl deleteLink = (WebControl)e.Row.Cells[3].Controls[0];
deleteLink.Attributes.Add("OnClick", "javascript:return CheckforDelete();");
}
2)Datarowview
DataRowView drv = (DataRowView)e.Row.DataItem;
string Player_Response = drv[""].ToString();
3)in row command
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
int Key = int.Parse(dg.DataKeys[row.RowIndex].Values[1].ToString());
if we r using paging in row command
int rindex = Convert.ToInt32(e.CommandArgument.ToString());
string MemberKey = GridView1.DataKeys[rindex - (GridView1.PageIndex * GridView1.PageSize)].Value.ToString();
4)Row deleting
GridView1.DataKeys[e.RowIndex].Value.ToString());
Boolean FixtureCancel = Convert.ToBoolean(DataBinder.Eval(e.Row.DataItem, "Fixture_Canceled"));
5)Row updating
Convert.ToInt32(GridTeamOfficials.DataKeys[e.RowIndex].Value.ToString());
Comments