Gridview几种点击获取值的方式(赠送一个REPEATER的)

1.多按钮法:

 

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

                  
        string com = e.CommandName.ToString();
       
        string id = e.CommandArgument.ToString();

}

 

2.TemplateField 方法

 
                   
                        修改
                   

               

 

protected void lnkbtnEdit_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        Response.Redirect("Dept.aspx?moduid="+Request["moduid"]+"&id="+id+"&action=update");
    }

 

3.CommandField 方法

 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
           
            string red = "xiugai.aspx?id=" + this.GridView1.DataKeys[e.NewEditIndex][0].ToString();
           
            Response.Redirect(red);
        }

 

4. 删除
   

protected void Del_Click(object sender, CommandEventArgs e)
        {
            b.Delete(Convert.ToInt32(e.CommandName));        }

 

你可能感兴趣的:(Gridview几种点击获取值的方式(赠送一个REPEATER的))