Solved

SelectedIndexChanged help with two radio buttons lists

Posted on 2013-01-09
10
445 Views
Last Modified: 2013-01-11
I have two radio button lists on one form.
I'm trying to have them both fire the calculation when each is changed.  It works correctly when the rblSessions has a selected value, then next has a selected value changed rblGuests.  It fires this:

protected void rblGuest_SelectedIndexChanged(object sender, EventArgs e)
        {          
            int c = 230;
            c += int.Parse(this.rblSessions.SelectedItem.Value) * int.Parse(this.rblGuests.SelectedItem.Value);
            tbFee.Text = string.Format("{0:d}", c);
}

Open in new window


If someone goes back and selects a new value for rblSessions, how do I get this code to fire again?  
It does work again when I select a new value from rblGuest, but there will be scenarios when the user will not do it.
Thanks.
0
Comment
Question by:javierpdx
  • 5
  • 5
10 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
Comment Utility
Two ways:
1: move you code in separate method and call the method from the SelectedIndexChanged event of both the rbls

Or
2: set the SelectedIndexChanged of rblSessions to rblGuest_SelectedIndexChanged and also make it AutoPostback
0
 

Author Comment

by:javierpdx
Comment Utility
When I set the autopostback="true" for ddlSessions, I can only select the firs two items of the drop down menu.  When I select the 3rd item of the drop down list, it goes back to item 2. Have you ever seen this issue?

This is my drop down menu:

<asp:DropDownList ID="ddlSessions" runat="server"
                        DataSourceID="SqlDataSourceTransfer" DataTextField="Title"
                        DataValueField="GuestFee" AutoPostBack="true"
                        onselectedindexchanged="ddlSessions_SelectedIndexChanged">
                    </asp:DropDownList>
0
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
It's not normal and so will have to see your code...
what do you  have in your ddlSessions_SelectedIndexChanged?
0
 

Author Comment

by:javierpdx
Comment Utility
I'm using this code in ddlSessions_SelectedIndexChanged:
 protected void ddlSessions_SelectedIndexChanged(object sender, EventArgs e)
        {            
                int c = 230;
                c += int.Parse(this.ddlSessions.SelectedItem.Value) * int.Parse(this.rblGuests.SelectedItem.Value);
                tbFee.Text = string.Format("{0:d}", c);                          
            }

Open in new window

0
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
Can you share all other code that involves your ddlSessions in any ways like binding or setting values or anything of that sort?

Oh and weren't we dealing with radiobuttonlist? How come it's dropdown now?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:javierpdx
Comment Utility
Sorry for the change, but I tried to switch between both drop down list and radio button list and see that they both are acting the same.
0
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
no problem...just wanted to make sure we are dealing with same problem and question.
Any more code to share?
0
 

Author Comment

by:javierpdx
Comment Utility
I found the issue but don't know how to resolve it.  The "DataValueField" item in my list box is set to the GuestFee field, but the guest fee for different sessions can be set to the same value.  
When AutoPostBack="true", my list box shows all the items, but only allows me to select the first two unique "DataValueField"s.  

for example:
Session A = 50
Session B = 100
Session C = 100
Session D = 100

(if I change the value for the Guest Fee, to unique values, the drop down list works)
Is there a way around this?  Or does that value need to be unique?
0
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 500 total points
Comment Utility
In that case you will have to make the values distinguishable.
e.g. here

And then when you want to use the value, you will have to extract the value from the modified value.
0
 

Author Closing Comment

by:javierpdx
Comment Utility
Thanks for the help.   I appreciate it.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now