【发布时间】:2022-01-04 02:35:20
【问题描述】:
我已经动态创建了一个下拉列表,一旦页面加载,一切都很好。在下拉菜单旁边的 gridview 的每一行中都有一个按钮。此按钮更新所选项目的表格。我得到了我的密钥,但我得到的对象引用未设置为实例。这是因为下拉控件的 id 隐藏在 ct100 的东西中吗?
Dim ddluid As String = CType(FindControl("Ddlos"), DropDownList).SelectedItem.Value
这里是我从页面来源刷的:
<select name="ctl00$ContentPlaceHolder2$GridView1$ctl02$Ddlos" id="ctl00_ContentPlaceHolder2_GridView1_ctl02_Ddlos">
<option value="0">-Select-</option>
<option value="503841a3-c615-4e4d-8cf5-20fbddbf7a7f">John Doe</option>
<option value="9b38e9cd-f16f-4fdd-a82e-501c866f9e45">Sam Beacon</option>
<option value="fe6158c5-a549-443f-b5ff-c011937db1d7">John Doey</option>
<option value="295e9f85-6ea6-46ec-9c00-c38d64023517">Scot King</option>
Protected Sub btnsaveinfo(sender As Object, e As EventArgs)
Dim key As String = ""
For Each row As GridViewRow In GridView1.Rows
If row.RowType = DataControlRowType.DataRow Then
key = GridView1.DataKeys(row.RowIndex).Value.ToString()
Dim ddluid As String = CType(FindControl("Ddlos"), DropDownList).SelectedItem.Value
'Dim idvalue As String = ddluid.SelectedValue
'Dim louid As Guid =
Dim cn As New SqlConnection(ConfigurationManager.ConnectionStrings("sqlConnectionString").ConnectionString)
Dim cmdupdate As New SqlCommand("update Profiles SET [loanrepid] = @loanrepid WHERE ApplicantID=@ApplicantID", cn)
cmdupdate.Parameters.AddWithValue("@loanrepid", "1")
cmdupdate.Parameters.AddWithValue("@ApplicantID", key)
cmdupdate.CommandType = System.Data.CommandType.Text
cmdupdate.Connection = cn
cn.Open()
cmdupdate.ExecuteNonQuery()
cn.Close()
End If
Next
lblresult.Text = " Details Updated Successfully"
lblresult.Visible = True
End Sub
<asp:TemplateField HeaderText="Loan Officer" SortExpression="Loan Officer" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:DropDownList ID="Ddlos" runat="server" Visible="false"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
【问题讨论】: