GridView内按钮Click之后取值

Reference Code:

protected void GridView1_RowCreated( object sender,GridViewRowEventArgse)
... {
if(e.Row.RowType==DataControlRowType.DataRow)
...{
if(e.Row.FindControl("Button1")!=null)
...{
Buttonbtn
=(Button)e.Row.FindControl("Button1");
btn.Click
+=newEventHandler(btn_Click);
}

}

}


private void btn_Click( object sender,EventArgse)
... {
Buttonbtn
=(Button)sender;
GridViewRowgvr
=(GridViewRow)btn.Parent.Parent;
stringpk=GridView1.DataKeys[gvr.RowIndex].Value.ToString();

this.Label1.Text=pk;
}

你可能感兴趣的:(GridView)