Solved

Binding to a Drop Down box with a sql server datasource

Posted on 2012-12-26
4
629 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

732 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