I have a gridviw with a bunch of rows, the first column contains checkboxes. I want the user to only select 3 different rows. If they select a fourth row the selection will be denied/undone/etc. I have labels above the gridview with the values of the ID from the row of the selected checkboxes. I need to update these labels as the user changes selections.
Here's my grid:
<asp:GridView ID="gv_pain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataSourceID="ds_grid_pain" ForeColor="Black" GridLines="Vertical" style="text-align: left; font-size: x-small; ">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBoxPain" runat="server" onclick="CheckCheck()" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DrugID" InsertVisible="False" SortExpression="DrugID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("DrugID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_DrugID" runat="server" Text='<%# Bind("DrugID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NickName" HeaderText="NickName" SortExpression="NickName" ItemStyle-Width="150px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="DrugName" HeaderText="DrugName" SortExpression="DrugName" ItemStyle-Width="500px">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan1" HeaderText="Quan1" SortExpression="Quan1">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Quan2" HeaderText="Quan2" SortExpression="Quan2">
<ItemStyle Wrap="False" />
</asp:BoundField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
The grid and the checkboxes are loaded on an event. The itemtemplate label is loaded correctly with the value I need in my textboxes. As users click the checkboxes it doesn't fire the same event to make changes to the textboxes. Here's the code that sets the textboxes for the first time:
ClearCheckBoxes(False)
Dim row As GridViewRow
For Each row In gv_pain.Rows
If row.RowType = DataControlRowType.DataRow Then
Dim lblDrugID As Label = row.FindControl("lbl_DrugID")
If lblDrugID.Text = dt.Rows(0)("pain1").ToString() Then
Dim cbPain As CheckBox = row.FindControl("CheckBoxPain")
cbPain.Checked = True
hlbl_pain1.Text = dt.Rows(0)("pain1").ToString()
End If
If lblDrugID.Text = dt.Rows(0)("pain2").ToString() Then
Dim cbPain As CheckBox = row.FindControl("CheckBoxPain")
cbPain.Checked = True
hlbl_pain2.Text = dt.Rows(0)("pain2").ToString()
End If
If lblDrugID.Text = dt.Rows(0)("pain3").ToString() Then
Dim cbPain As CheckBox = row.FindControl("CheckBoxPain")
cbPain.Checked = True
hlbl_pain3.Text = dt.Rows(0)("pain3").ToString()
End If
End If
Next
There's nothing special about these labels. I need their values because I'm using them somewhere else.... so I need them to reflect the latest 3 selected checkboxes. Here they are:
<asp:Label ID="hlbl_pain1" runat="server" Text="Label" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain2" runat="server" Text="Label" Visible="true"></asp:Label>
<asp:Label ID="hlbl_pain3" runat="server" Text="Label" Visible="true"></asp:Label>
<asp:Label ID="hlbl_scar1" runat="server" Text="Label" Visible="true"></asp:Label>
<asp:Label ID="hlbl_scar2" runat="server" Text="Label" Visible="true"></asp:Label>
<asp:Label ID="hlbl_migraine1" runat="server" Text="Label" Visible="true"></asp:Label>
<asp:Label ID="hlbl_migraine2" runat="server" Text="Label" Visible="true"></asp:Label>
<asp:Label ID="hlbl_eczema1" runat="server" Text="Label" Visible="true"></asp:Label>
How do I: 1) Stop the 4th check box from being checked? 2) Change the values of the labels as any of the 3 allowed checkboxes change?
Thanks
Aucun commentaire:
Enregistrer un commentaire