在GridView中添加全选功能,并获取选中行id

 

 

 

 

 

 

 

后台代码:

    ///


    /// 获取选中行id
    ///

    ///
    ///
    protected void Button1_Click(object sender, EventArgs e)
    {
        string mgs="";
        //循环遍历GridView行中的控件
        for (int i = 0; i         {
            CheckBox cb = (GridView1.Rows[i].FindControl("CheckBox2")) as CheckBox;
            if (cb.Checked ==true )//判断是否选中
            {
                //把获取的id用逗号联结,然后赋给label
                mgs += ((this.GridView1.Rows[i].FindControl("LblId")) as Label).Text+",";//找到模版中储存id的label
                lblMgs.Text = mgs.Substring(0, mgs.Length - 1);
            }
        }
    }

 

页面调用的Javascript代码:

   

 

在input标签的onclick事件中调用:

               
                   
                        全选
                   

                   
                       
                   

                   
               

 

页面代码:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ControlBind.aspx.cs" Inherits="ControlBind" %> 无标题页

 
全选 删除      

你可能感兴趣的:(ASP.NET,asp,server,textbox,button,javascript,input)