views:

26

answers:

1

I am new to asp.net and know little bit about its working and as I am moving forward I am getting new and more newer doubts.

Here at this point I was working with two RadioLists that are being binded at page load.

Now when a user changes the index of radio button in list 1. Second needs to get updated accordingly depending what value is currently set for selected radio button. Since the page will be posted back hence I either need to fire a query again to get new data from DataBase for currently selected index or can store 2-3 tables in session in form of Dataset.

What should I do in such scenario. Should I fire an sql query again or retrieve DataSet from Session.

What is the most optimal approach for this. And WHY ?

+1  A: 

The data for radio button list 1 (rbl1) should not be retrieved again from the database. It should already be populate from the ViewState. This is an invisible object on your page that keeps track of the contents of your controls between loading them into the browser and returning the form back to the server. If you rebind rbl1 to the data on a postback, you will lose the current selection.

There should be nothing wrong with retrieving the data for the send radiobuttonlist from the database if the results are going to change depending on the selection of the first.

However, if the size of the data is small you might want to cache the results to the application cache, if all users see the same set of data, or the session cache if it is user-dependent.

Then you can use Linq to query the data based on the selection from the first radiobuttonlist.

<asp:RadioButtonList ID="rbl1" runat="server" AutoPostBack = "true"
 OnSelectedIndexChanged="rbl1_SelectedIndexChanged">

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
       //bind your rbl1 here
    }
}

protected void rbl1_SelectedIndexChanged(object sender, EventArgs e)  
{  
     //load your second radio button list depending on the selection of the first
}  
Daniel Dyson