Repeater

P

Peter Kirk

Hi there

I have some c# code which extracts a list of data (an array of Port objects)
from a database, and I need to display this data on an asp, where the user
can see and edit the data (and press a "save" button to write changes back
to the database).

I am using a "repeater" to list the Port items on the page, where some of
the attributes of the Port objects are textboxes where the user can edit the
data.

My problem is the "save" button - for this I have an onclick handler, but
how does the list of Port objects get supplied to the onclick method so I
can write to the database?

Thanks for any help,
Peter
 
S

S.M. Altaf [MVP]

Peter,

The Save button is a single button and is not repeated, correct?

In the button's Click event, declare textbox variables that correspond to
the textboxes in each row of the repeater.

foreach(RepeaterItem rItem in rptRepeater.Items)
{
txtPort1 = (TextBox)rItem.FindControl("txtPortName");
txtPort2 = (TextBox)rItem.FindControl("txtPortPrice"); //Other
processing. }Where I've written 'other processing', you can take the
values in the textboxes, and save them back to the database. This will get
performed for each row of the repeater.
HTH
S.M. Altaf - MVP VB
 
P

Peter Kirk

S.M. Altaf said:
Peter,

The Save button is a single button and is not repeated, correct?

In the button's Click event, declare textbox variables that correspond to
the textboxes in each row of the repeater.

foreach(RepeaterItem rItem in rptRepeater.Items)
{
txtPort1 = (TextBox)rItem.FindControl("txtPortName");
txtPort2 = (TextBox)rItem.FindControl("txtPortPrice"); //Other
processing. }Where I've written 'other processing', you can take the
values in the textboxes, and save them back to the database. This will
get performed for each row of the repeater.
HTH
S.M. Altaf - MVP VB

Great, thanks.
Peter
 
P

Peter Kirk

S.M. Altaf said:
Peter,

The Save button is a single button and is not repeated, correct?

The save button is in the "Footer" section of the repeater.
Do you know how I can stop the footer from being processed if the repeater
list is empty? For example, if there is no list then I don't want the save
button to be dsiplayed.

Thanks,
Peter
 
P

Peter Kirk

Peter Kirk said:
The save button is in the "Footer" section of the repeater.
Do you know how I can stop the footer from being processed if the repeater
list is empty? For example, if there is no list then I don't want the save
button to be dsiplayed.

OK, I found out I can check <% if (myList.Items.Count > 0) ....
 

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,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top