【发布时间】:2018-10-31 16:28:55
【问题描述】:
我已经断断续续地处理这个问题好几个星期了,包括许多互联网搜索。似乎没有什么与我正在尝试做的事情一致。我在 SQL Server 中有五个布尔字段。我可以毫无问题地更新它们并将它们显示在标签字段中。编辑模式在 checkBoxList 中构造它们,但我没有得到要显示的数据库值。这是 OnRowEditing 代码:
Protected Sub EmplSumm_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles EmplSummGridView.RowEditing
WriteToFile.WTF("EmployeeSummary.EmplSumm_RowEditing:" & e.NewEditIndex.ToString, Gbl.LogPath)
Try
UpdateIndex = e.NewEditIndex
EmplSummGridView.EditIndex = e.NewEditIndex
Dim SQLStm As String = "SELECT W4State, W4Allowances, W4Exempt, " &
"IdSocialSecurity, IdBirthCert, IdDriverLic, IdPassport, IdPermit " &
"From EmploymentInfo " &
"Where emplid = '" & EmplSummGridView.DataKeys(e.NewEditIndex).Values(0).ToString() & "'; "
Dim connection As New SqlConnection(connectionString)
Dim adapter As New SqlDataAdapter(SQLStm, connection)
Dim dt1 As New DataTable()
adapter.Fill(dt1)
'Dim row As GridViewRow = EmplSummGridView.Rows(UpdateIndex)
WriteToFile.WTF("EmployeeSummary.EmplSumm_RowEditing:" & "|" & UpdateIndex & "|" & dt1.Rows(0).Item("IdSocialSecurity").ToString, Gbl.LogPath)
Dim cbSecBirth As CheckBoxList = TryCast(EmplSummGridView.Rows(e.NewEditIndex).FindControl("cbSecBirthCertE"), CheckBoxList)
cbSecBirth.Items(0).Selected = Convert.ToBoolean(dt1.Rows(0).Item("IdSocialSecurity"))
cbSecBirth.Items(1).Selected = Convert.ToBoolean(dt1.Rows(0).Item("IdBirthCert"))
cbSecBirth.Items(2).Selected = Convert.ToBoolean(dt1.Rows(0).Item("IdDriverLic"))
cbSecBirth.Items(3).Selected = Convert.ToBoolean(dt1.Rows(0).Item("IdPassport"))
cbSecBirth.Items(4).Selected = Convert.ToBoolean(dt1.Rows(0).Item("IdPermit"))
cbSecBirth.DataBind()
WriteToFile.WTF("EmployeeSummary.EmplSumm_RowEditing cbSecBirth:" & "|" & cbSecBirth.Items(0).Selected _
& "|" & cbSecBirth.Items(1).Selected & "|" & cbSecBirth.Items(2).Selected _
& "|" & cbSecBirth.Items(3).Selected & "|" & cbSecBirth.Items(4).Selected, Gbl.LogPath)
Catch ex As Exception
Dim S As String = ex.Message + vbCrLf
S = S + "Help Link:" + ex.HelpLink + vbCrLf
S = S + "Source:" + ex.Source + vbCrLf
S = S + "Stack Trace:" + ex.StackTrace + vbCrLf
'lblerror.Text = "System Error - System Error - Employee_ItemUpdating: " & S
WriteToFile.WTF("Exception in EmployeeSummary.EmplSumm_RowEditing:" & Now() & "|" & S, Gbl.LogPath)
End Try
End Sub
和 ASP:
<asp:Templatefield HeaderText="SecBirthCertDL" SortExpression="SecBirthCertDL" ItemStyle-CssClass="tableitem1">
<ItemTemplate>
<asp:Label ID="lblId" runat="server" readonly ="True"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBoxList ID="cbSecBirthCertE" runat="server" autopostback="false" >
<asp:ListItem Text="SS Card" ></asp:ListItem>
<asp:ListItem Text="Birth Certificate" ></asp:ListItem>
<asp:ListItem Text="Drivers License" ></asp:ListItem>
<asp:ListItem Text="Passport" ></asp:ListItem>
<asp:ListItem Text="Permit" ></asp:ListItem>
</asp:CheckBoxList>
</EditItemTemplate>
</asp:Templatefield>
从数据库到 CheckBoxList 的值已正确设置,例如:cbSecBirth.Items(0).Selected 但在呈现表单时不显示。下面是 WriteToFile 函数的输出: EmployeeSummary.EmplSumm_RowEditing cbSecBirth:|True|True|False|False|False
【问题讨论】:
-
EmployeeSummary.EmplSumm_RowEditing cbSecBirth:|True|True|False|False|False
标签: asp.net vb.net gridview checkboxlist