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

 

posted on 2009-03-02 11:32  轻狂如我,奋华图强  阅读(337)  评论(0)    收藏  举报