Use of "Repeater" control to loop through data rows

Discussion in 'ASP .Net Web Controls' started by donnet, Jan 12, 2005.

  1. donnet

    donnet Guest

    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.
     
    donnet, Jan 12, 2005
    #1
    1. Advertising

  2. 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:


    "donnet" <> wrote in message
    news:...
    >
    > 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.
     
    Elmer Carías, Jan 13, 2005
    #2
    1. Advertising

  3. donnet

    JDP@Work Guest

    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...


    "Elmer Carías" <> wrote in message
    news:uTCavWQ%...
    > 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:
    >
    >
    > "donnet" <> wrote in message
    > news:...
    > >
    > > 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.

    >
    >
     
    JDP@Work, Jan 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fraggle

    loop through rows in a table

    Fraggle, Nov 19, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    16,618
    Pat Alessi
    Nov 24, 2003
  2. sck10
    Replies:
    2
    Views:
    5,461
    sck10
    Sep 12, 2006
  3. Paul
    Replies:
    2
    Views:
    9,736
  4. addi
    Replies:
    0
    Views:
    271
  5. Isaac Won
    Replies:
    9
    Views:
    382
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page