我正在尝试根据数据集的结果检查我的复选框。Memory_Error 是数据库中的列。保存数据时,我将插入 1 或 0 作为字符串。我已经查看并查看并寻找有关如何执行此操作的示例,但似乎没有一个可以完成工作。我没有收到任何错误,我只是在应该检查时得到一个未选中的复选框。提前感谢您的任何帮助。如果我的解释不够简洁,我深表歉意。
这是我的 vb.net 代码。
Dim dap2 As New SqlDataAdapter("Select ID, Store, Status, Reason, Detail, Detail_1, Detail_2, Detail_3, Information, Memory_Error, Detail_4 FROM PollDetail where Poll_Date = '" & pollDate & "'", conn)
conn.Open()
Dim ds2 As New DataSet
dap2.Fill(ds2, "PollDet")
gvEmailRes2.DataSource = ds2
Dim i As Integer
For i = 0 To gvEmailRes2.Rows.Count - 1
'-------------ckbMemErr-----------------------------------------------------------------/////
If ds2.Tables("PollDet").Rows(i).Item(9) = "1" Then
Dim row2Fill As GridViewRow = gvEmailRes2.Rows(i)
Dim cbMemErr As CheckBox = DirectCast(row2Fill.FindControl("ckbMemErr"), CheckBox)
cbMemErr.Checked = True
ElseIf ds2.Tables("PollDet").Rows(i).Item(9) = "0" Then
Dim row2Fill As GridViewRow = gvEmailRes2.Rows(i)
Dim cbMemErr As CheckBox = DirectCast(row2Fill.FindControl("ckbMemErr"), CheckBox)
cbMemErr.Checked = False
End If
Next
gvEmailRes2.DataBind()
conn.Close()
dap2.Dispose()
这是 ASP.NET
<asp:TemplateField HeaderText="Memory Error" SortExpression="Memory_Error" ItemStyle- VerticalAlign="Top">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<br />
<asp:CheckBox ID="ckbMemErr" runat="server" Text="Memory Error" Font-Size="11px" />
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
</asp:TemplateField>