Attaching a value to RadioButtons in a Repeater

J

JesperGJensen

I need to select a date from a list of possible dates. I do this
through a Repeater

<asp:Repeater>
<ItemTemplate>
<RadioButton OnCheckedChanged="rptSelect_Changed">
<asp:Label> a date </asp:Label>
</ItemTemplate
</asp:Repeater>

In my current testcase there are 7 days to choose from. I use the
rptSelect_Changed function to handle the selection Serverside.
But how do i attach the date information to each RadioButton?
Currently i can only get basic RadioButton object. But this
radiobutton object does not know which date it represents.
When i did something similar with LinkButtons in a repeater i used
CommandArgument to attach the information.

How do i attach information to a radiobutton in this setup?
 
C

Coskun SUNALI [MVP]

Hi Jesper,

Try using the following code. In this sample, I find the parent control of
the RadioButton and get the Label placed in the same parent control. You can
access other child controls you may want to add in case you need to store
some other data inside them. (I haven't tried executing the code)

<asp:Repeater>
<ItemTemplate>
<RadioButton ID="rbDate" runat="server"
OnCheckedChanged="rptSelect_Changed">
<asp:Label ID="lbDate" runat="server"> a date </asp:Label>
</ItemTemplate
</asp:Repeater>


protected void rptSelect_Changed(object sender, EventArgs e)
{
RadioButton m_RB = (RadioButton)sender;
RepeaterItem m_RI = (RepeaterItem)m_RB.Parent;
Label m_L = (Label)m_RI.FindControl("lbDate");
string m_DateString = m_L.Text;
}

--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top