protected void imgBtnUp_Click(object sender, ImageClickEventArgs e)
{
ImageButton imageBtn = sender as ImageButton;
GridViewRow Row = imageBtn.NamingContainer as GridViewRow;
int id = Row.RowIndex;
}
参考上面的代码,其中id就是点击gridview中的BUTTON后怎么获得BUTTON所在行的索引值。
Button bt = (Button)sender;//接收bt
DataControlFieldCell dcfc = (DataControlFieldCell)bt.Parent;
GridViewRow gvr = (GridViewRow)dcfc.Parent;//父控件
GridView1.SelectedIndex = gvr.RowIndex;//行值
string key = "";
key= GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString();
事件在protected void Button1_Click1(object sender, EventArgs e)中写
其中key为BUTTON>>bt所在行的索引值键值 ,不知你能明白,可以加在代码中用一下.
把绑的id 设置为主键然后
GridView1.DataKeys[e.RowIndex].Value.ToString();