Link to home
Start Free TrialLog in
Avatar of badrhino
badrhinoFlag for United States of America

asked on

Binding to a Drop Down box with a sql server datasource

I'm starting to play with JQuery a little and I would like to bind data from a sql server to a drop down box (just to learn how).  The code behind has to be in vb.net.

I have looked at several examples on the web but they either C# or vb.net and don't work/aren't complete.  Does anyone know of a good walkthrough that I can play with?

Thanks in advanced!
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

Try these,

Approach 1 . Binding dropdown using vb.net


Protected Sub Button1_Click1(sender As Object, e As EventArgs)

dim str As String = "Data Source=.;uid=sa;pwd=wintellect;database=rohatash"

	Dim con As New SqlConnection(str)
Dim anyFilter as string= ""
	Dim cmd As New SqlCommand("select textColumn,valueColumn from UserDetail where id = '" & anyFilter & "'", con)

	Dim Adpt As New SqlDataAdapter(cmd)

	Dim dt As New DataTable()

	Adpt.Fill(dt)

	ddl1.DataSource = dt

	ddl1.DataBind()
ddl1.DataTextField="textColumn"
ddl1.DataValueField="valueColumn"


End Sub

Open in new window

Approach 2 : Using SqlDatasource control .
Binding Dropdown using SqlDatasource control without codebehind .
http://asp-net-example.blogspot.in/2008/12/aspnet-sqldatasource-example-using.html
Sqldatasource connectionstring parameter is configured in web.config file .
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
<connectionStrings>
  <add 
    name="NorthwindConnectionString" 
    connectionString="Data Source=serverName;Initial 
    Catalog=Northwind;Persist Security Info=True;User 
    ID=userName;Password=password"
    providerName="System.Data.SqlClient"
  />
</connectionStrings>

Open in new window


More Info Regarding Connection string ,
http://msdn.microsoft.com/en-us/library/ms178411(v=vs.100).aspx

Meeran03
Avatar of badrhino

ASKER

This works great for server side code, but how do you do it with JQuery?
ASKER CERTIFIED SOLUTION
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect. Thanks!