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;
    }
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/insus/article/details/2123970
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭