我遇到了 CheckBox oncheckchanged 事件的问题。
该复选框位于网格视图中,如果选中该复选框,我希望一个按钮可见。
如果选中一个或多个复选框,则按钮变为可见,但未选中第一个复选框时,即使选中另一个复选框,按钮也会变为不可见。
请求帮助
<asp:Button ID="BtnRequestCartons" runat="server" Text="Request Cartons"
BorderStyle="Ridge" onclick="BtnRequestCartons_Click" Visible="False" />
<asp:GridView ID="GridViewcrtreq" runat="server" AllowPaging="False"
AutoGenerateColumns="False" DataSourceID="SqlDataSource5" CellPadding="0"
ForeColor="#333333" GridLines="None" PageSize="5" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px" ShowFooter="true" Width="100%"
HeaderStyle-CssClass="gvHeader"
>
<AlternatingRowStyle BackColor="white" ForeColor="#284775" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<tr class="gvHeader" align="right">
<th style="width:0px"></th>
<th colspan="3">
</th>
</tr>
<tr class="gvHeader">
<th></th>
<th>
<asp:CheckBox ID="chkSelectAll" runat="server" Text="" onclick="javascript:SelectAllCheckboxes(this);"/>
</th>
<th align="left">Carton ID</th>
<th align="left">Carton Status</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelectAdd" OnCheckedChanged="GridViewcrtreq_OnCheckedChanged" runat="server" AutoPostBack="True" />
<td align="left"><%# Eval("CartonID")%></td>
<td align="left"><%# Eval("CartonStatus")%></td>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="White" Font-Bold="True" ForeColor="Black" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1" />
<HeaderStyle BackColor="#D6D6C2" Font-Bold="True" ForeColor="Black" HorizontalAlign="Center" BorderWidth="1" BorderStyle="Solid" BorderColor="#999999" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" BorderColor="Silver" BorderWidth="1" BorderStyle="Solid" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
protected void GridViewcrtreq_OnCheckedChanged(object sender, EventArgs e)
{
CheckBox chkSelectAdd = sender as CheckBox;
if (chkSelectAdd.Checked == true)
{
BtnRequestCartons.Visible = true;
}
if (chkSelectAdd.Checked == false)
{
BtnRequestCartons.Visible = false;
}
}