Use of "Repeater" control to loop through data rows

D

donnet

I come from J2EE and starting to learn ASP.NET.
I want to find a way to display a web form filled with data taken from a SQL
table. I need to repeat the layout of my web form in one single page, each
time with data taken from the SQL table row. I don't want to put those data
rows into a datagrid because I have my own form that I want to populate with
a specific html layout. And I'm not sure the "Repeater" control is a solution
to my problem.

With J2EE, I would have the use of Java Beans where I would loop and store
each table row information into a class bean and then add each bean into an
ArrayList. Then I would pass this ArrayList to my .JSP page (the equivalent
of .aspx) where I would iterate through my ArrayList to get each bean's
methods using a java scriplet tag to put my "for" loop.

How can i do the equivalent of Java beans in ASP.NET? Can someone give me a
sample codes of the .aspx.cs file and .aspx file showing how you can repeat a
web form and populating with information taken from each table row?

Can I use "Repeater" controls to repeat the display of a web form with
labels, tables, textboxes and textareas and being able to loop through data
rows in order to populate the web form?

Thanks a bunch.
 
E

Elmer Carías

your best way to do that is use DataList, in the item template of DataList
you put your Html layout with server controls, and use the property
databinding to the controls, to do that you need set the datasource of
datalist, and DataBind the datalist.

The link i put use example with DataRepeater, but you can use same with
DataList
http://www.openmymind.net/databinding/

Elmer Carías
El Salvador, CA
MSN: (e-mail address removed)
 
J

JDP@Work

Additionally you may wish to consider the following......

Since .Net allows you to use mulitple tables in a result set...

exec usp_GetClient_Order_Summary @clientID

returns....

--table(0)
select accID ,company ,contact ... from contact1 where .....= @someVar

--table(1)
select accID ,orders ,orderID ... from orders where .....= @someVar

--table(2)
select accID ,order_Details ,orderID ... from Order_Det where .....= @someVar


You can bind to these other tables, but not until you bound to table(0)

For example if I want the whole form to be one record and in the center section
display all the invoices and details for each in nested repeaters I must do so
only after the databind for table(0)

'snipit
Private Sub FillForm(ByVal AcctNo As String)

dsOrderSummary = SqlHelper.ExecuteDataset(Common.ConnectionString,
"usp_getOrders", AcctNo)

Me.OrderSummary.DataSource = dsLead.Tables(0)
Me.OrderSummary.DataBind()

dsOrderSummary.Dispose()

End Sub

Private Sub OrderSummary_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
OrderSummary.ItemDataBound

'use public dsOrderSummary dataset to populate inner repeaters
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

Dim rpt As Repeater = e.Item.FindControl("OrderSummary_Orders")

rpt.DataSource = dsOrderSummary.Tables(1)
rpt.DataBind()

rpt = e.Item.FindControl("OrderSummary_OrderDetail")
rpt.DataSource = dsLead.Tables(2)
rpt.DataBind()

End If
End Sub

As you can see it's tricky but can be done and is an important aspect of using a
repeater to display meaningful data as a full page form.

HTH

JeffP...
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top