Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello.

i have designed a webform by ASP.net 4 & using Sqlserver 2008r2 , in my form there is a Dropdownlist that includes names of countries .my qeustions:

1- for the better performance i don't whether is this good to add items (name of countries ) in ASp.net (dropdownlist item collection) or to

bind them to my database , table of Country?

2- when i put dropdownlist in my form and run the solution there is no scroll bar for dropdownlist ? how can i activate it?

if i use HTML Select option , i don't know how to bind it to database..
Posted

1 solution

//To bind the data to dropdownlist in html
XML
<select name="" id="" style="WIDTH: 200px" class="clsListBox">
                        <% call FillCombo() %>
                    </select>

VB
Sub FillCombo()
SqlCon.open()
Dim sqlcmd As SqlCommand = New SqlCommand("SP Name", sqlcon)
        sqlcmd.CommandType = CommandType.StoredProcedure

        Dim da As SqlDataAdapter = New SqlDataAdapter(sqlcmd)

        Dim dr As SqlDataReader

        dr = sqlcmd.ExecuteReader()
        Dim intComboID As Integer = 0
               While dr.Read()

            Response.Write("<option value='" & intComboID & "'dr.Item("Name") & "</option>")
                       intComboID = intComboID + 1

        End While
         dr.Close()
        dr = Nothing
        sqlcon.Close()
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900