Hello,
I am trying to get the values of CheckBoxes in a GridView, but when i try this the CheckBox is always false.
Here is the code.
Private Sub lbUpdatePricing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbUpdatePricing.Click
For Each r As GridViewRow In gvProductBrowser.Rows
Dim txtBox As New TextBox
Dim chkBox As CheckBox = CType(r.FindControl("chkNoSale"), CheckBox)
txtBox = CType(r.FindControl("txtNewPrice"), TextBox)
Dim productID As Integer = CInt(gvProductBrowser.DataKeys(r.RowIndex).Value)
If Not String.IsNullOrEmpty(txtBox.Text) And IsNumeric(txtBox.Text) And Not txtBox.Text = "0.00" Then
Call UpdateProductPricing(productID, CDec(txtBox.Text))
End If
Call UpdateProductDisabled(productID, chkBox.Checked)
Next
Call LoadData()
End Sub
And on the front end the HTML looks like:
<asp:GridView ID="gvProductBrowser" runat="server"
GridLines="None"
AutoGenerateColumns="False"
DataKeyNames="ProductID"
CssClass="Grid"
CellPadding="0"
CellSpacing="0"
BorderWidth="0"
AllowPaging="false"
AllowSorting="True"
OnSorting="gvProductBrowser_Sorting"
>
<Columns>
<asp:TemplateField ItemStyle-Width="15" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<asp:CheckBox ID="chkNoSale" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="75">
<HeaderTemplate>
<asp:linkbutton runat="server" ID="SortSku" CommandName="sort" CommandArgument="Sku" Text="Sku"></asp:linkbutton>
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="hlSku" runat="server" Text='<%# Eval("Sku") %>' NavigateUrl='<%# GetNavigateUrl(Eval("Sku"))%>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I have read in some articles that there are problems with the GridView and CheckBoxes but have not been able to solve the problem.
Any help would be appreciated,
- Walter Manger