ASP.NET: Deserializing server side object
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?
- In the Page_Load(), I queried the table to fetch the list of years into an arraylist.
- Serialized the arraylist using JavaScriptSerializer.
Questions:
- I know I need to deserialize the server side object. But how do I access it in using jQuery?
- Am I taking the correct approach to solve the problem?
Pardon me开发者_StackOverflow in case my questions and approach is naive. Do guide me on this.
cheers
Do you have to do it this way? Why not use a RadioButtonList
?
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 union all select 2008 as year union all select 2007 as year union all select 2006 as year union all select 2005 as year">
</asp:SqlDataSource>
</div>
</form>
精彩评论