[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Binding to a Drop Down box with a sql server datasource

Posted on 2012-12-26
4
Medium Priority
?
644 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…
Suggested Courses

649 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