protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.FindControl("Button1") != null)
{
Button btn = (Button)e.Row.FindControl("Button1");
btn.Click += new EventHandler(btn_Click);
}
}
}
![]()
private void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.Parent.Parent;
string pk = GridView1.DataKeys[gvr.RowIndex].Value.ToString();
![]()
this.Label1.Text = pk;
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.FindControl("Button1") != null)
{
Button btn = (Button)e.Row.FindControl("Button1");
btn.Click += new EventHandler(btn_Click);
}
}
}
private void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.Parent.Parent;
string pk = GridView1.DataKeys[gvr.RowIndex].Value.ToString();
this.Label1.Text = pk;
}

浙公网安备 33010602011771号