<asp:GridView ID="Note1" runat ="server" AutoGenerateColumns="False" 
                                        CaptionAlign="Top" BorderStyle="None" BorderWidth="0px" Width="100%">
                               
                               <Columns>
                               <asp:TemplateField>
                                <ItemTemplate>
                             <asp:CheckBox ID="chkSelect"    runat="server"  onclick="javascript:checkAll('chkAll',this);" />                                </ItemTemplate>
                                   <HeaderStyle Width="3%" />
                            </asp:TemplateField>                               <asp:BoundField DataField="CreateDate"  HeaderText="编写时间"  
                                       DataFormatString="{0:yyyy-MM-dd}"    >
                              
                                   <HeaderStyle CssClass="f-hei12" Width="14%" />
                                  <ItemStyle Wrap="False"  CssClass="f-hei12" />
                                   
                                   </asp:BoundField>
                              
                               <asp:BoundField DataField="NoteContent" HeaderText="摘 要" >
                               <HeaderStyle CssClass="f-hei12" Width="72%" /> 
                                   <ItemStyle Wrap="False" CssClass="f-hei12" />
                                   </asp:BoundField>
                                                             </Columns>
                               </asp:GridView>  private string  GetCheckbox() 
     {         string sb = "";
         for (int i = 0; i <= Note1.Rows.Count - 1; i++)
         {
             CheckBox cbox = (CheckBox)Note1.Rows[i].FindControl("chkSelect");             if (cbox.Checked == true)
             {                 //note.Delete(int.Parse(Note1.DataKeys[i].Value.ToString()));
                 sb += Note1.DataKeys[i].Value.ToString() + ",";             }
           
         }
         return sb;
     }获取不到所选啊,我调试都是false

解决方案 »

  1.   

    你的前台的checkbox选中了吗?
    checkAll()这个js怎么写的?
      

  2.   

    当然选中了,我点单选一个,或者全选都不行
    function checkAll(chkAllID,thisObj) 

        var chkAll = document.getElementById(chkAllID); 
        var chks = document.getElementsByTagName("input"); 
        var chkNo = 0; 
        var selectNo = 0; 
        for(var i =0; i < chks.length; i++) 
        { 
           if(chks[i].type == "checkbox") 
           { 
              //全选触发事件   
              if(chkAll == thisObj) 
              { 
                 chks[i].checked = thisObj.checked;              
              }           
              //非全选触发 
              else 
              { 
                if(chks[i].checked && chks[i].id != chkAllID) 
                 selectNo++; 
              } 
              if(chks[i].id != chkAllID) 
              { 
                chkNo++; 
              } 
           } 
        }  
        if(chkAll != thisObj) 
        { 
            chkAll.checked = chkNo==selectNo; 
        } 
    }function checkSelectNo(chkAllID) 

        var chks = document.getElementsByTagName("input"); 
        var selectNo =0; 
        for(var i =0; i < chks.length; i++) 
        { 
           if(chks[i].type == "checkbox") 
           { 
                if(chks[i].id != chkAllID && chks[i].checked) 
                { 
                    selectNo++; 
                } 
           } 
        }   
        return selectNo; 
    }
      

  3.   

    checkbox的onclick的时候,它的checked状态还没改呢!
    你的逻辑错了。
      

  4.   

    换成:input 的 checkbox<asp:GridView ID="Note1" runat ="server" AutoGenerateColumns="False" CaptionAlign="Top" BorderStyle="None" BorderWidth="0px" Width="100%"> 
    <Columns> 
         <asp:TemplateField> 
             <ItemTemplate> 
    <INPUT type="checkbox" name="ckb"  onclick="javascript:checkAll('chkAll',this);"
             </ItemTemplate> 
          <HeaderStyle Width="3%" /> 
          </asp:TemplateField> 
     <asp:BoundField DataField="CreateDate"  HeaderText="编写时间"  DataFormatString="{0:yyyy-MM-dd}"    > 
     <HeaderStyle CssClass="f-hei12" Width="14%" /> 
      <ItemStyle Wrap="False"  CssClass="f-hei12" /> 
       </asp:BoundField> 
       <asp:BoundField DataField="NoteContent" HeaderText="摘 要" > 
        <HeaderStyle CssClass="f-hei12" Width="72%" /> 
          <ItemStyle Wrap="False" CssClass="f-hei12" /> 
         </asp:BoundField> 
         </Columns> 
        </asp:GridView>private string  GetCheckbox() 
        {
       string strValue=Request["ckb"];
    return strValue;
    }
      

  5.   

    DataKeyNames="menberid"  girdview加入datakeynames解决