Solved

SelectedIndexChanged help with two radio buttons lists

Posted on 2013-01-09
10
462 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Install Problem 13 31
Question! 4 36
Store results in vb.net 3 20
What is Microsoft.Exchange.WebServices.Data.ExchangeService in PowerShell? 4 26
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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