Solved

Binding to a Drop Down box with a sql server datasource

Posted on 2012-12-26
4
627 Views
Last Modified: 2012-12-26
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!
0
Comment
Question by:badrhino
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38721613
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
0
 
LVL 1

Author Comment

by:badrhino
ID: 38721649
This works great for server side code, but how do you do it with JQuery?
0
 
LVL 18

Accepted Solution

by:
Rajar Ahmed earned 500 total points
ID: 38721687
You are looking for AJAX using jquery,
The below example matches  your requirement .
http://www.aspdotnet-suresh.com/2012/07/how-to-bind-dropdownlist-in-aspnet.html
Walkthrough:
1.Use Jquery Ajax functionality
2.Create WebMethod in your page and assign it on the url of jquery ajax .
3.Webmethod returns array .
4.Loop through the array and bind the dropdown on success of jquery ajax ,

More Advanced.
http://www.aspsnippets.com/Articles/AJAX-Cascading-DropDownList-using-jQuery-in-ASP.Net.aspx

Meeran03
0
 
LVL 1

Author Closing Comment

by:badrhino
ID: 38721857
Perfect. Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now