Getting IDs back when submitting

J

Josh Valino

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
 
S

Sergey Zyuzin

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

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
 
J

Josh Valino

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
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top