在asp.net的gridview里面的复选框

时间:2013-12-22 05:44:07

标签: asp.net

我在gridview中使用复选框:

<asp:TemplateField>
    <HeaderTemplate>
        <asp:CheckBox ID="chkhdr" runat="server" AutoPostBack="true"  />
    </HeaderTemplate>
    <ItemTemplate>
         <asp:CheckBox CssClass="gridrownormal3" ID="chkChild" runat="server" />                          
    </ItemTemplate>
</asp:TemplateField>

按钮单击以绑定网格:

 protected void Button1_Click(object sender, EventArgs e)
 {
     /*
      * Clear All Data in Grid By Calling Empty_GridView
      * */
      if (this.IsValid)
      {
           Empty_GridView(grdDocList_Summary);
           List<SearchEngineEO> doc = Docs;
           var query18 = (from c in doc 
                          select new { c.DocNO, c.DocType, c.Title, c.Padid,
                                         c.PublisherName, c.PublishedDate, 
                                         c.Rade }).Distinct().ToList();
           grdDocList_Summary.DataSource = query18;
           grdDocList_Summary.DataBind();
      }
} 

我在运行时选中了复选框,我想显示这些行的一些细节。 我使用这段代码:

 for (int i = 0; i < grdDocList_Summary.Rows.Count; i++)
 {
      GridViewRow row = grdDocList_Summary.Rows[i];
      bool isChecked = ((CheckBox)row.FindControl("chkChild")).Checked;

      if(isChecked)
      {
           String str = row.Cells[1].Text;
           DocNos.Add(str);
      }
 }

假设我在grdDocList_Summary中有10行。当我选择一个复选框时,对于上面变量ischecked的所有迭代都为真。为什么会这样?

0 个答案:

没有答案