Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Getting IDs back when submitting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh Valino - 08 Feb 2008 17:12 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.