Solved

binding sql server data to a html Select

Posted on 2014-02-24
2
1,425 Views
Last Modified: 2014-02-25
I saw this example, it's close to what I need but not exactly.

Binding to a SELECT
http://samples.msdn.microsoft.com/workshop/samples/author/databind/dbselect.htm

Anyone know of a example where I bind either XML or JSON data to a HTML select?

I'm getting the data from sql server and generating an xml or json file and then I want to bind that to an HTML select.
0
Comment
Question by:maqskywalker
[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 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39885349
Assume your json looks like
http://jsbin.com/fibohece/1.js
{
    "country": "France"
}

Open in new window

Your html
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<select datasrc="#tdcComposer" datafld="origin">
<option value="Austria">Austria
</option><option value="France">France
</option><option value="Germany">Germany
</option><option value="Italy">Italy
</option><option value="Russia">Russia
</option></select>
 
</body>
</html>

Open in new window

jquery
// Sample data http://jsbin.com/fibohece/1.js
$(function() {
$.getJSON("/fibohece/1.js", function (data) {
    var origin = data.country;
    $("select[datafld='origin']  option").each(function () {
        if ($(this).val() === origin) {
            $(this).prop('selected', true);

        }
    });


});
});

Open in new window

Working sample http://jsbin.com/hikexefa/1/edit using the url for json http://jsbin.com/fibohece/1.js.  If you are accessing a url from a different domain, you have to use jsonp instead of json.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

617 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