2014-11-24 95 views
0

我已經當我所有的<asp:CheckBox ID="chkApprove">檢查網格視圖asp.net網格視圖複選框

<cc1:GridView ID="gvMenu" runat="server" AllowPaging="False" AllowSorting="False" 
          AutoGenerateColumns="False" CssClass="mGrid" Width="100%" DataKeyNames="ID,MenuName" 
          DataSourceID="OdsGetMenuDetails" OnRowDataBound="gvMenu_RowDataBound"> 
    <%--OnRowDataBound="gvAddLeave_RowDataBound"--%> 
    <AlternatingRowStyle CssClass="alt" /> 
    <HeaderStyle CssClass="GridViewHeaderStyle" /> 
    <PagerStyle CssClass="pgr" /> 
    <RowStyle Wrap="false" /> 
    <EmptyDataRowStyle BackColor="#edf5ff" Height="300px" HorizontalAlign="Center" VerticalAlign="Middle" /> 
    <EmptyDataTemplate> 
    No Records Found 
    </EmptyDataTemplate> 
    <Columns> 
    <asp:TemplateField HeaderText="Sr.No"> 
     <ItemTemplate> 
     <%# (gvMenu.PageIndex * gvMenu.PageSize) + Container.DataItemIndex + 1%> 
     </ItemTemplate> 
     <HeaderStyle CssClass="style4" ForeColor="White" Width="5%" /> 
     <ItemStyle CssClass="style4" /> 
    </asp:TemplateField> 
    <asp:BoundField DataField="ID" HeaderText="Menu ID" SortExpression="ID" Visible="false"> 
     <HeaderStyle CssClass="style4" Width="100px" HorizontalAlign="Left" ForeColor="White" /> 
     <ItemStyle CssClass="style4" /> 
    </asp:BoundField> 
    <asp:BoundField DataField="MenuName" HeaderText="MenuName" SortExpression="MenuName"> 
     <HeaderStyle CssClass="style4" Width="80%" HorizontalAlign="Left" ForeColor="White" /> 
     <ItemStyle CssClass="style4" /> 
    </asp:BoundField> 
    <asp:TemplateField HeaderText="View"> 
     <HeaderTemplate> 
     <asp:CheckBox ID="chkHeaderApprove" runat="server" Text="View" onclick="javascript:SelectAllCheckboxes1(this);" /> 
     </HeaderTemplate> 
     <ItemTemplate> 
     <asp:CheckBox ID="chkApprove" runat="server" Checked='<%# Eval("ViewStatus").ToString().Trim() == "1" ? true : false %>' /> 
     </ItemTemplate> 
    </asp:TemplateField> 
    </Columns> 
</cc1:GridView> 

這個ObjectDataSource控件

<asp:ObjectDataSource ID="OdsGetMenuDetails" runat="server" SelectMethod="GetMenuName" 
          EnablePaging="true" TypeName="AdsWorksDBMenuAuthorizationDAL" StartRowIndexParameterName="startIndex" 
          SortParameterName="sortBy" MaximumRowsParameterName="pageSize" SelectCountMethod="GetMenuCount"> 
</asp:ObjectDataSource> 

我想要做的<asp:CheckBox ID="chkHeaderApprove" >檢查?

我不能做到這一點,請幫助我多些....

+0

不能理解..你可以分享輸入 - >輸出,或更多的解釋? – 2014-11-24 11:52:23

+0

好吧,先生只是一分鐘 – SachinD 2014-11-24 11:59:26

回答

0

補充一點:

<asp:CheckBox ID="chkApprove" runat="server" Checked='<%# Eval("ViewStatus").ToString().Trim() == "1" ? true : false %>' OnCheckedChanged="chkApprove_CheckChanged"/> 

而且在後面的代碼:

protected void chkApprove_CheckChanged(object sender, EventArgs e) 
    { 
     CheckBox cb = (CheckBox)sender; 
     GridView g1 = (GridView)cb.Parent.Parent; 
     foreach (GridViewRow item in g1.Rows) 
     { 
      CheckBox currentCheckBox = (CheckBox)item.FindControl("chkApprove"); 
      if (currentCheckBox.Checked != true) 
       return; 
     } 
     CheckBox chkHeaderApprove = (CheckBox)g1.FindControl("chkHeaderApprove"); 
     chkHeaderApprove.Checked = true; 
    } 

這應該工作。沒有檢查。反正客戶端應該更好,去那個..這只是一個簡單的服務器端解決方案。