使用另一个类的下拉列表数据绑定?
Dropdownlist 数据绑定使用公共的 throw 函数。在传递下拉列表时遇到问题。
错误:对象无法设置对象的实例
代码如下
Aspx 页面代码:
<asp:DropDownList ID="ddlagent1" CssClass="ParameterTextBox" runat="server" AutoPostBack="false"></asp:DropDownList>
Protected Sub chkcity_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkcity.CheckedChanged
ldstOption = //fill values here
lobjGeneral.loadComboBox1(Me.ddlagent1, ldstOption.Tables(0), "No Data found")
End Sub
常规类:
Public Sub loadComboBox1(ByVal cbo As DropDownList, ByVal dset As DataTable, ByVal msgstr As String, _
Optional ByVal visible As Boolean = True, _
Optional ByVal enabled As Boolean = True, _
Optional ByVal tno As Integer = 0, _
Optional ByVal dmem As Integer = 2, _
Optional ByVal vmem As Integer = 1)
Try
If (dset.Rows.Count > 0) Then
cbo.DataSource = dset
cbo.DataTextField = dset.Columns(dmem).Caption
cbo.DataValueField = dset.Columns(vmem).Caption
cbo.DataBind()
cbo.SelectedIndex = 0
cbo.Visible = visible
cbo.Enabled = enabled
Else
dset = Nothing
cbo.Text = msgstr
End If
Catch ex As Exception
'Call CreateErrorLogFile("General", "loadComboBox", Err.Description)
End Try
End Sub
The Dropdownlist data binding using throw common function. In this have a problem in passing dropdownlist.
Error: Object cannot be set an instance of object
The code is below
Aspx Page Code:
<asp:DropDownList ID="ddlagent1" CssClass="ParameterTextBox" runat="server" AutoPostBack="false"></asp:DropDownList>
Protected Sub chkcity_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkcity.CheckedChanged
ldstOption = //fill values here
lobjGeneral.loadComboBox1(Me.ddlagent1, ldstOption.Tables(0), "No Data found")
End Sub
General Class:
Public Sub loadComboBox1(ByVal cbo As DropDownList, ByVal dset As DataTable, ByVal msgstr As String, _
Optional ByVal visible As Boolean = True, _
Optional ByVal enabled As Boolean = True, _
Optional ByVal tno As Integer = 0, _
Optional ByVal dmem As Integer = 2, _
Optional ByVal vmem As Integer = 1)
Try
If (dset.Rows.Count > 0) Then
cbo.DataSource = dset
cbo.DataTextField = dset.Columns(dmem).Caption
cbo.DataValueField = dset.Columns(vmem).Caption
cbo.DataBind()
cbo.SelectedIndex = 0
cbo.Visible = visible
cbo.Enabled = enabled
Else
dset = Nothing
cbo.Text = msgstr
End If
Catch ex As Exception
'Call CreateErrorLogFile("General", "loadComboBox", Err.Description)
End Try
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的方法应该必须获得 Dropdownlist 引用
Your method should have to get Dropdownlist reference