使用另一个类的下拉列表数据绑定?

发布于 2024-11-08 12:35:35 字数 1569 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷梦 2024-11-15 12:35:35

您的方法应该必须获得 Dropdownlist 引用

Public Sub loadComboBox1(ByRef cbo As DropDownList, ......

Your method should have to get Dropdownlist reference

Public Sub loadComboBox1(ByRef cbo As DropDownList, ......
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文