mardi 25 octobre 2016

VB.NET checkbox problems

Web site in Visual Studio 2010 with VB. I created a GridView with a checkbox column, but my code behind is not recognizing the checked rows. Runs through with no error but never sees a checked row.

 <asp:GridView 
    ID="gvwOrderDetails" 
    DataKeyNames="ID"
    runat="server" 
    BackColor="White" 
    BorderColor="#DEDFDE" 
    BorderStyle="None" 
    BorderWidth="1px" 
    CellPadding="4" 
    ForeColor="Black" 
    GridLines="Vertical">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="OrderSelector" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#CCCC99" />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
    <RowStyle BackColor="#F7F7DE" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#FBFBF2" />
    <SortedAscendingHeaderStyle BackColor="#848384" />
    <SortedDescendingCellStyle BackColor="#EAEAD3" />
    <SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>


Protected Sub btnVoid_Click(sender As Object, e As System.EventArgs) Handles btnVoid.Click

        Dim atLeastOneRowVoided As Boolean = False
        For Each row As GridViewRow In gvwOrderDetails.Rows

            Dim cb As CheckBox = TryCast(row.Cells(0).FindControl("OrderSelector"), CheckBox)

                If cb IsNot Nothing AndAlso cb.Checked Then
                     atLeastOneRowVoided = True
                     Dim orderID As Integer = _
                    Convert.ToInt32(gvwOrderDetails.DataKeys(row.RowIndex).Value)
                lbl1.Text &= String.Format( _
                    "This would have voided ProductID {0}<br />", orderID)

            End If
        Next

    End Sub




Aucun commentaire:

Enregistrer un commentaire