Solved

how to get the selected item value of RadioButtonList which is inside Accordion ???

Posted on 2008-10-10
5
1,229 Views
Last Modified: 2013-12-17
Hello experts,

           I am using a RadiobuttonList inside Accordion. The Radiobuttonlist is set to AutoPostBack = true. So I want to capture the value of selectedItem of radioButtonlist when the item is selected.I want to do this in c#.

Urgent..Thanks.
<div class="AccordionPanel">

                                                <ajaxToolkit:Accordion ID="Accordion1" runat="server" SelectedIndex="1" FadeTransitions="true" 

                                                FramesPerSecond="40" TransitionDuration="250" AutoSize="None" RequireOpenedPane="false" 

                                                HeaderCssClass="HeaderTab" ContentCssClass="ContentTab">

                                                  

                                                </ajaxToolkit:Accordion>

                                            </div>
 
 

public void accordion()

    {

        DataSet dsDistibutors = Fund.GetAllDistibutor();

        AccordionPane ap1 = new AccordionPane();

        ap1.HeaderContainer.Controls.Add(new LiteralControl("Select Distributor"));

        ap1.ContentContainer.Controls.Add(GetRadioButtonList());

        Accordion1.Panes.Add(ap1);

    }

    private RadioButtonList GetRadioButtonList()

    {

        DataSet dsDistibutors = Fund.GetAllDistibutor();

        RadioButtonList RBList = new RadioButtonList();

        RBList.DataSource = dsDistibutors;

        RBList.DataTextField = "USER_NM";

        RBList.DataValueField = "USER_NM";

        RBList.DataBind();

        RBList.AutoPostBack = true;

        return RBList;

    }

Open in new window

0
Comment
Question by:srk1982
  • 3
5 Comments
 
LVL 15

Expert Comment

by:NazoUK
ID: 22686470
Add an event Handler in your GetRadioButtonList() function:

RBList.SelectedIndexChanged +=new EventHandler(RBList_SelectedIndexChanged);

then add a new function to handle the event:

protected void RBList_SelectedIndexChanged(object sender, EventArgs e)
{
       RadioButtonList RBList = sender as RadioButtonList;
       ...
}

You can then get the selected value from within this new function
0
 

Author Comment

by:srk1982
ID: 22686612
Hi NazoUK,

        i am using vs2005.   I know where to add the eventhandler in vs2003.
        where to add this vs2005???


Thanks....
0
 
LVL 15

Accepted Solution

by:
NazoUK earned 500 total points
ID: 22687783
Sorry, I wasn't very clear there. The line

RBList.SelectedIndexChanged +=new EventHandler(RBList_SelectedIndexChanged);

is adding the event handler. Just add that line into GetRadioButtonList() after the line RBList.AutoPostBack = true;

Note that to work properly the GetRadioButtonList() function must be called every postback but I assume you're probably doing that anyway or your radiobuttonlist would disappear after you change the selectedindex.
0
 

Expert Comment

by:agenteg
ID: 22690391
Catching the event only allow you to get the selected value when the user changes it, but if you want to get it whenever you want (without using global variables), even if the user don't change the value, try this:

First, set the Tag property of the RadioButtonList as, ie, "RBList"...

then:

object  FindRBListValue(Control control)
{
    foreach(Control child in control.Controls)
      {
        if (child.Tag is string)
            if (string.Compare("RBList", child.Tag) == 0)
              return (child as RadioButtonList ).Value;
       object childs = FindRBListValue(child);
      if (childs != NULL)
         return childs;
       }
return null;
}


Call this method like this:

...
object listValue = FindRBListValue(this);
if (listValue == NULL)
   throw (new Exception("Could not found Radio Button List");


Try this, I'm not good at ASP.net, but should make the deal...

0
 
LVL 15

Expert Comment

by:NazoUK
ID: 22690676
That's inefficient and completely unnecessary though, if he wants to find the radio button list he can do it using the FindControl method of the Accordion.

RadioButtonList rbl = (RadioButtonList) ap1.ContentContainer.FindControl("<RBLID>")

but I'm guessing as he's set autopostback=true he wants to react to that event.
I just noticed the ID property of the RadioButtonList isn't being set though which is probably a good idea.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

21 Experts available now in Live!

Get 1:1 Help Now