views:

104

answers:

2

Hi

I am new to ASP.NET, AJAX, JSON, jQuery and am trying to figure out a solution to the following problem:

There is this web page in ASP.NET which would contain few radio buttons. The page_load() would query SQL Server database and get a list of years i.e. 2009, 2008, 2007, 2006 etc. In the client side script, I need to create as many radio buttons as the number of years returned. For e.g. if the query returns 2009, 2008, 2007, 2006, then the page should show 4 radio buttons. I have an upper bound on the number of years which can be returned, so I intend to create that many radio buttons and do a show/hide based on the number of years returned.

What I have done so far?

  1. In the Page_Load(), I queried the table to fetch the list of years into an arraylist.
  2. Serialized the arraylist using JavaScriptSerializer.

Questions:

  1. I know I need to deserialize the server side object. But how do I access it in using jQuery?
  2. Am I taking the correct approach to solve the problem?

Pardon me in case my questions and approach is naive. Do guide me on this.

cheers

A: 

Do you have to do it this way? Why not use a RadioButtonList?

John Saunders
Yes, that sounds to be a good option. But I need to be able to make multiple selects. Does the radioButtonList allow such behavior? If not then I might have to try a checkBoxList.
Andriyev
In fact I have one more page which ought to have a grid of check boxes. Some thing like this http://weblogs.asp.net/jgalloway/archive/2007/07/07/checkbox-grids-in-asp-net.aspx Again the row and column header list would be obtained from database i.e. I can't fix it before hand. How do I handle this?
Andriyev
A: 

Try something like this.

<form id="form1" runat="server">
    <div>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataSourceID="SqlDataSource1"
            DataTextField="year" DataValueField="year">
        </asp:RadioButtonList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tempdbConnectionString %>"
            SelectCommand="Select 2009 as year&#13;&#10;union all&#13;&#10;select 2008 as year&#13;&#10;union all&#13;&#10;select 2007 as year&#13;&#10;union all&#13;&#10;select 2006 as year&#13;&#10;union all&#13;&#10;select 2005 as year">
        </asp:SqlDataSource>
    </div>
</form>
solairaja