我想从html页面上GridView中得到一个checkbox是否checked,  
但是不管checkbox是否选中,checkbox.checked的值始终为false!  
不知道用什么方法呢?  

解决方案 »

  1.   

    //找到第i行j列里面的第m个控件,假设这个控件就是checkbox
    CheckBox checkbox = gv.Rows[i].Cells[j].Controls[m];然后再使用,应该没问题了
      

  2.   

    写错...改下
    CheckBox checkbox = (CheckBox)gv.Rows[i].Cells[j].Controls[m];
      

  3.   

    我是在GridView里把一列都设成CheckBox的啊...值我是取到了可是总是false....
      

  4.   

    我说的i行j列就是遍历用的啊...至于为何总是false..你把代码贴出来吧
      

  5.   

    你不会把CheckBox的ID都写成一个了吧
      

  6.   

    热烈祝贺ASP.NET群7947148成立了。
      

  7.   

    <asp:GridView ID="GV" runat="server" AutoGenerateColumns="False" Font-Names="新細明體"
                    Font-Size="Small" Height="133px" Width="5000px" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="GV_RowDataBound" OnRowCreated="GV_RowCreated"  >                            
                    <Columns>
                        <asp:BoundField />
                        <asp:TemplateField>                        
                            <ItemTemplate>
                                <asp:CheckBox ID="chkSelect" runat="server" />
                             </ItemTemplate>
                        </asp:TemplateField>
    <asp:BoundColumn DataField="AS003" HeaderText="(原文件名)" Visible="False"></asp:BoundColumn>
                                <asp:BoundColumn DataField="AS007" HeaderText="上傳時間">
                                    <ItemStyle Font-Size="X-Small" HorizontalAlign="Center" />
                                    <HeaderStyle Width="160px" />
                                </asp:BoundColumn>
                                <asp:BoundColumn DataField="AS004" HeaderText="(存儲文件名)" Visible="False"></asp:BoundColumn>
                                <asp:BoundColumn DataField="AS005" HeaderText="(擴展名)" Visible="False"></asp:BoundColumn>
                                <asp:BoundColumn DataField="AS006" HeaderText="(存儲路徑)" Visible="False"></asp:BoundColumn>
    </Columns>
    </asp:GridView>
    protected void ButtonDel_Click(object sender, EventArgs e)
        {
            CheckBox selection;       
            foreach (GridViewRow myItem in this.GV.Rows)
            {
                selection = (CheckBox)myItem.FindControl("chkSelect");            
                if (selection.Checked == true)
                {
                    .........
                 }
             }
         }
      

  8.   

    你是不是
    没有将你的数据绑定代码放到if(!IsPostBack)
    {
    //GridView绑定处理..
    }
      

  9.   

    protected void Page_Load(object sender, EventArgs e)
        {
            string mySql = "SELECT * FROM NPLPilotRun WHERE 1=1";
            this.Data_Bind(mySql);
        }
        private void Data_Bind(string SqlString)
        {
            SqlConnection myConn = myDB.GetDBConnection();
            int CountIndex;
            SqlDataAdapter myDA = new SqlDataAdapter(SqlString, myConn);
            System.Data.DataTable myDT = new System.Data.DataTable("PilotRun");
            myDA.Fill(myDT);
            this.GV.DataSource = myDT;
            this.GV.DataBind();
          }  
    我是这样绑定的啊
      

  10.   

    我想你可能和我遇到同样的问题了.不过我后来解决了.你看一下.你在页面加载的时候是不是没有写这一句话.
    if(!Page.IsPostBack )
    {}
      

  11.   

    我也碰到同样的问题了。把数据绑定放在if(!Page.IsPostBack) {...}中是解决问题了;但是,这样的话 我的 BandData()过程必须放在if(!Page.IsPostBack) {...}外该怎么办
      

  12.   

    我找到问题的所在了,就是把数据邦定的时候回传了,写到(!ispostback)就没事了,嘿嘿。