Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SelectedIndexChanged help with two radio buttons lists

Posted on 2013-01-09
10
Medium Priority
?
488 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 2000 total points
ID: 38761051
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
ID: 38764278
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
ID: 38764294
It's not normal and so will have to see your code...
what do you  have in your ddlSessions_SelectedIndexChanged?
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:javierpdx
ID: 38764310
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
ID: 38764325
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
 

Author Comment

by:javierpdx
ID: 38764462
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
ID: 38764663
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
ID: 38765267
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 2000 total points
ID: 38765348
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
ID: 38768447
Thanks for the help.   I appreciate it.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

971 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