Hi,
I have a webform that lists poeple from a database and has a radiobutton
list for each person. I want to go down the list and select a radio button
for each person, then save those selections to a database. But in order to
save the selections to the database, I need to get back the ID of the person
who is associated with each radiobutton list. How do I make this
association? I am generating my list in a repeater like so:
<asp:Repeater ID="r1" runat="server">
<ItemTemplate>
<tr>
<td width="50%">
<asp:Label ID="lblName" runat="server" />
</td>
<td>
<asp:RadioButtonList ID="rad" runat="server">
<asp:ListItem Value="Phone" Text="Phone" />
<asp:ListItem Value="Mail" Text="Mail" />
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
My data source is a datatable that would look like this if viewed as raw
data:
PersonID PersonName ContactMethod
1 Joe Smith [this is what I need to update]
2 Mary Jones
I want to have a method that will loop through all the radiobutton lists
that wound up being created and save the selection for each given person, by
PersonID. I'm still stuck in the classic ASP way of thinking where I'd just
name the radiobuttons rad<%=personID%> and then parse it back out of the
items in the form collection when submitted. How do I achieve this in .net?
2.0
TIA,
Josh
Eliyahu Goldin - 10 Feb 2008 09:52 GMT
You may consider switching to the GridView and use the DataKeys collection.
If you want to stick with the Repeater, you can pass the id in a hidden
column:
<td style="display:none">here goes id</td>

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
> Hi,
>
[quoted text clipped - 38 lines]
>
> Josh
Sergey Zyuzin - 10 Feb 2008 10:36 GMT
> Hi,
>
[quoted text clipped - 38 lines]
>
> Josh
I have similar suggestion as Eliyahu, you can add
something like <asp:Literal runat="server" id="hello" Visible="false"
Text="<%# bind id here %>"/> to each item.
So you can access this control in the same way you access other
controls (and retrieve Id from Text property) and it's text won't go
to client
so you'll have the same html on client you have now.
HTH,
Sergey
Josh Valino - 11 Feb 2008 16:53 GMT
Thanks for the suggestions (to Eliyahu too). I'll do a hidden-field of some
sort. I can't take using datagrids or most of the .net controls because of
the way they render html with in-line styles and how the datagrid doesn't
use the <th> tag. (Maybe that's different these days.)
Thank you
Josh
I have similar suggestion as Eliyahu, you can add
something like <asp:Literal runat="server" id="hello" Visible="false"
Text="<%# bind id here %>"/> to each item.
So you can access this control in the same way you access other
controls (and retrieve Id from Text property) and it's text won't go
to client
so you'll have the same html on client you have now.
HTH,
Sergey