Binding to a ddl but using a Class

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I have a dropdownlist. I want to read the data from database and populate it.
I know I can do it in the code behind by populating a dataset..as explained in this link:
http://www.experts-exchange.com/Web/Q_21489607.html

But I like to create a class, in my code-behind call that Class and populate the ddl..

I know how to create the class, but what should be passed to it from my code-behind, what should the "return" value of the function be? If someone could give me an outline/class shell..that would be good too. Thanks
 
I don't know if this would work, but you could make a function that uses ByRef instead of ByVal, which would allow you to directly munipulate the object in the function, and then just return a True value if it was successful, and a false if it failed.
 
That worked, thanks. I'm following this example to add color to the background of my DropdownList ..not sure why mine doesnt work:

http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp

Code:
Public Function GetDll(ByRef retval As DataSet, ByRef ddlRptName As DropDownList) As DataSet

...
Dim cmd As New SqlClient.SqlCommand("usp_rt_get_reportFiles", cnn)
Dim da As New SqlDataAdapter(cmd)
...
da.Fill(retval)

            Dim i As Integer
            For i = 0 To retval.Tables(0).Rows.Count - 1
                ddlRptName.Items.Add(New ListItem(retval.Tables(0).Rows(i)("NewName")))
                ddlRptName.Items(i).Attributes.Add("style", "color:red")

            Next
...

Return retval
..
 
Sorry, It doesnt show the color. It's still "black".

I also tried:

Code:
ddlRptName.Items(i).Attributes.Add("style",[b] "Background-color:red"[/b] + ddlRptName.Items(i).Text)

But the background is still white.
 
Found my answer. I have to use "<select>" and not "<asp:dropdownlist>" control. Missed that in the article.
 
Back
Top