使用VB的Visual Studio 2010中的网站。我创建了一个带复选框列的GridView,但后面的代码却没有识别出已检查的行。运行时没有错误,但从未看到已检查的行。
<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