Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 426353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:28:15+00:00 2026-05-12T19:28:15+00:00

I am trying to create a simple ajax grid that allows me to add

  • 0

I am trying to create a simple ajax grid that allows me to add and remove rows and also edit some of the columns and have others columns calculated directly based on the input in the others. I thought this would be a nice oppurtunity to play with asp.net ajax 4.0 and the client templates. It works pretty ok but I can’t seem to find a way to bind my json data to a . How can I do this?

A normal template looks like this

<div id="authorsTemplate" style="visibility:hidden;display:none;"> 
    <ul> 
        <li>First Name: {{ FirstName }}</li> 
        <li>Last Name: {{LastName}}</li> 
        <li>Url: <a href="{{Url}}">{{Url}}</a></li> 
    </ul> 
</div> 

How would I use the data bind syntax with a dropdown

<select id="">
  <option value="1">1</option>
  <option value="2">2</option>
</select>

EDIT:
If the select tag had a value attribute the obvious solution would be.
Edit2:
The syntax below was actually the solution, Thx Roatin, I had no idea the select actually had a value attribute.

<select id="" value="{binding nr}">
    <option value="1">1</option>
    <option value="2">2</option>
</select>

I could maybe use custom javascript to set the selected option but the point is a live binding to my json object the same way you bind to the value of a input tag

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:28:16+00:00Added an answer on May 12, 2026 at 7:28 pm

    I do not want to populate the dropdown, it is already populated. I want to be able to use the client template binding syntax to get the value from my json object and set the selected element.

    In fact, select DOM elements do have a value property (but not exposed as an attribute in the markup). Setting it is equivalent to (and faster than) iterating the child <option>s and setting the selectedIndex to the found option index of the option that has a matching value.

    Anyway, here’s how to bind to it directly with Sys.Binding (complete test case):

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <style type="text/css">.sys-template {display:none}</style>
        <script src="MicrosoftAjax.debug.js"></script>
        <script src="MicrosoftAjaxTemplates.debug.js"></script>
    
        <script type="text/javascript">
        var dataItem = { Foo: '3' };
        function pageLoad()
        {
            $create(Sys.Binding, {
                target: $get("list"),
                targetProperty: 'value',
                source: dataItem,
                path: 'Foo',
                mode: Sys.BindingMode.twoWay
            });
        }
        </script>
    </head>
    <body>
      <select id="list">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
      </select>
    </body>
    </html>
    

    Here is how to do the same thing declaratively, if you prefer:

    <body xmlns:sys="javascript:Sys"
          xmlns:binding="javascript:Sys.Binding"
          sys:activate="*">
    
      <select id="list"
        sys:attach="binding"
        binding:target="{{ $get('list') }}"
        binding:targetproperty="value"
        binding:source="{{ dataItem }}"
        binding:path="Foo">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
      </select>
    

    (and of course get rid of the pageLoad JavaScript stuff…)

    Both examples set up two-way binding to the dataItem object. You can see when the page loads, the third <option> is selected as that is the option with a value matching dataItem.Foo. When you select a different item from the drop-down, dataItem.Foo updates with the new value selected.

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a simple page that enters data in to a
I'm new to postgreSQL and I have a simple question: I'm trying to create
I am trying to create a simple dialog in MFC using Visual C++. My
I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able
I'm trying to create a simple toggling sidebar using jquery, where it expands and
I'm playing with the ASP.NET MVC Framework, trying to create a simple site. My
I am trying to create a rather simple effect on a set of images.
Im using Eclipse 3.4, EclipseMe 1.7.9. Im trying to deploy/create package a simple project
I'm trying to come up with a simple and efficient way to create a
I'm trying to create simply connect with ActiveMQ using JNDI. I have: Queue named

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.