开发者

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?

  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开发者_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&#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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜