GridView内按钮Click之后取值

 Reference Code:

  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;
    }

你可能感兴趣的:(object,String,null,button,reference)