Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SelectedIndexChanged help with two radio buttons lists

Posted on 2013-01-09
10
Medium Priority
?
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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