Dropdownlist databind使用另一个类?

时间:2011-05-17 08:38:11

标签: .net asp.net vb.net drop-down-menu

使用throw公共函数的Dropdownlist数据绑定。这在传递下拉列表时遇到问题。

错误:对象无法设置对象的实例

代码在

之下

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

1 个答案:

答案 0 :(得分:2)

您的方法应该获得Dropdownlist参考

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