Solved

SelectedIndexChanged help with two radio buttons lists

Posted on 2013-01-09
10
483 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 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
Stressed Out?

Watch some penguins on the livecam!

 

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
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…

627 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