Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access control properties within nested repeater?

Status
Not open for further replies.

EDB2

MIS
Sep 11, 2002
36
US
I'm attempting to teach myself ASP.NET and VB2005 and I'm definately struggling. Any help would be greatly appreciated!

I have a series of radiobuttons within a nested repeater, and I need to know which button the user selects. I also want to change the appearance of the selected button.

As far as I can see, I'd need to use the ItemCommand event of the nested repeater but I can't figure out how to get to it. I tried adding an 'onItemCommand' parameter to the nested repeater but the event doesn't seem to fire.

Below is my code for the nested repeaters. Everything works great as far as displaying the data, but I can't interact with it.

<asp:Repeater ID="RepFactor" runat="server" OnItemDataBound="GetQuestions" >
<HeaderTemplate><table></HeaderTemplate>
<ItemTemplate>
<tr>
<td ><%#DataBinder.Eval(Container.DataItem, "Factor_Title")%></td>
</tr>
<tr>
<td>
<asp:Repeater ID="RepQuestions" runat="server" >
<HeaderTemplate><table></HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#DataBinder.Eval(Container.DataItem, "Question_No")%></td>
<td><%#DataBinder.Eval(Container.DataItem, "Question_Text")%></td>
<td>
<asp:RadioButton ID="rbEO" runat="server" GroupName="btns" />
<asp:RadioButton ID="rbFM" runat="server" GroupName="btns" />
<asp:RadioButton ID="rbMO" runat="server" GroupName="btns" />
<asp:RadioButton ID="rbNI" runat="server" GroupName="btns" />
<asp:RadioButton ID="rbLN" runat="server" GroupName="btns" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
 
use a radio button list instead of individual radio buttons. then use the RadioButtonList.SelectedValue to get the current selected value. if you want the RBL to fire the postback set RadioButtonList.AutoPostBack = true and assign an event handler to the SelectedIndexChange event.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thank you for the tips, I'll give that a try (unfortunately I'll have to wait until tomorrow to try it as I'm at home battling a cold today). It seems like I would have the same problem though - for the SelectedIndexChange event for instance, how do I reference it? The parent that holds that control is not available for a direct reference because it's a nested control. I can try adding an 'onSelectedIndexChange' to the nested repeater but that didn't work when I tried adding an onItemCommand.

My problem is not so much what properties/events to use, as how to reference those properties/events when they are on controls which are in a control which is nested within another control.

 
all web controls have FindControl(string ID); use this to find the control. You must cast the control to the base type you need.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
So I would use x = OuterRepeater.FindControl(InnerRepeater), then y = x.FindControl(RadioButtonList) and that would get me to the properties of the RadioButtonList, such as y.checked...correct? (I know that's not proper syntax, I'm just winging it)

How would I reference the SelectedIndexChange event?

I apologize if these are stupid questions, I'm definately not at my best today with this cold!
 
edb2 said:
So I would use x = OuterRepeater.FindControl(InnerRepeater), then y = x.FindControl(RadioButtonList) and that would get me to the properties of the RadioButtonList, such as y.checked...correct? (I know that's not proper syntax, I'm just winging it)
correct. you may need to cast the control to at least a webcontrol.
Code:
webcontrol x = (webcontrol)OuterRepeater.FindControl("InnerRepeater");
webcontrol y = x.FindControl("RadioButtonList");
btw this is c#, vb is slightly different.

once you get to the desired control you would assign the event like this (again c#, vb has different syntax)
Code:
private void SomeMethod()
{
   RadioButtonList rbl = (RadioButtonList)x.FindControl("MyRadioButtonList");
   rbl.SelectedIndexChanged += new EventHandler(rbl_SelectedIndexChanged);
}

private void rbl_SelectedIndexChanged(object sender, eventargs e)
{
   RadioButtonList rbl = (RadioButtonList)sender;
   string value = rbl.selectedvalue;
   //process request
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top