srk1982
asked on
how to get the selected item value of RadioButtonList which is inside Accordion ???
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.
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;
}
ASKER
Hi NazoUK,
i am using vs2005. I know where to add the eventhandler in vs2003.
where to add this vs2005???
Thanks....
i am using vs2005. I know where to add the eventhandler in vs2003.
where to add this vs2005???
Thanks....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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...
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...
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.FindC ontrol("<R BLID>")
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.
RadioButtonList rbl = (RadioButtonList) ap1.ContentContainer.FindC
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.
RBList.SelectedIndexChange
then add a new function to handle the event:
protected void RBList_SelectedIndexChange
{
RadioButtonList RBList = sender as RadioButtonList;
...
}
You can then get the selected value from within this new function