开发者

Dropdownlist databind using another class?

The Dropdownlist data binding using throw common function. In th开发者_运维技巧is 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


Your method should have to get Dropdownlist reference

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜