DataList - How to programmatically add a separator row

Discussion in 'ASP .Net Web Controls' started by Tony_VBACoder, Nov 20, 2007.

  1. With ASP.NET 2.0 VB.NET, how do I:

    I have a multi-column (4 columns) DataList control on my WebForm that
    displays sports teams for our league. The data is grouped by Division Names
    where there are 4 teams per Division. When the data is displayed on the Web
    Page, it will be a 4x4 (4 columns by 4 rows) grid. What I need to be able to
    do is, add a separator row whenever the Division Name changes and display
    that Division name such that it spans across 4 columns.

    I have a stored procedure that sorts the data by Division name, so the data
    is already coming in sorted by Division. All I need to be able to do is
    detect when the Division name changes, and then add a new row to the DataList.

    I have done something similar using a GridView control and the "Protected
    Overrides Sub Render(ByVal writer As HtmlTextWriter)" event, but I can't seem
    to find any examples of how to do this with a DataList control.
    Tony_VBACoder, Nov 20, 2007
    #1
    1. Advertising

  2. Hi, Tony

    What I use to do in such cases is more a hack than proper code, but
    I'd add on the ItemDataBound event check whenever the name of the
    league changes and add a Literal control to the DataListItem that
    would create the proper HTML to render the line.

    Although some try and err might be required to achieve the desired
    result.

    Regards,

    Paulo Santos
    http://pjondevelopment.50webs.com

    On Nov 20, 12:27 am, Tony_VBACoder
    <> wrote:
    > With ASP.NET 2.0 VB.NET, how do I:
    >
    > I have a multi-column (4 columns) DataList control on my WebForm that
    > displays sports teams for our league. The data is grouped by Division Names
    > where there are 4 teams per Division. When the data is displayed on the Web
    > Page, it will be a 4x4 (4 columns by 4 rows) grid. What I need to be able to
    > do is, add a separator row whenever the Division Name changes and display
    > that Division name such that it spans across 4 columns.
    >
    > I have a stored procedure that sorts the data by Division name, so the data
    > is already coming in sorted by Division. All I need to be able to do is
    > detect when the Division name changes, and then add a new row to the DataList.
    >
    > I have done something similar using a GridView control and the "Protected
    > Overrides Sub Render(ByVal writer As HtmlTextWriter)" event, but I can't seem
    > to find any examples of how to do this with a DataList control.
    PJ on Development, Nov 22, 2007
    #2
    1. Advertising

  3. Could you provide me with some code on how to add a Literal Control that will
    span across the columns? I have the following code in my DataList
    (dlstOwners) control's ItemDataBound event that does the compare, and it
    works, but I don't understand how to go about adding the Literal Control:

    Private Sub dlstOwners_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataListItemEventArgs) Handles
    dlstOwners.ItemDataBound
    If (e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    ListItemType.AlternatingItem) Then
    Dim sDiv As String = Convert.ToString((CType(e.Item.DataItem,
    DataRowView)).Row.ItemArray(4).ToString())
    ' Compare it to the previous one
    If sDiv <> msPrevDiv Then
    ' Add a new separator row spanning across the 4 columns that
    will display the Division
    ' Store it in the holding variable
    msPrevDiv = sDiv
    End If
    End If
    End Sub


    "PJ on Development" wrote:

    > Hi, Tony
    >
    > What I use to do in such cases is more a hack than proper code, but
    > I'd add on the ItemDataBound event check whenever the name of the
    > league changes and add a Literal control to the DataListItem that
    > would create the proper HTML to render the line.
    >
    > Although some try and err might be required to achieve the desired
    > result.
    >
    > Regards,
    >
    > Paulo Santos
    > http://pjondevelopment.50webs.com
    >
    > On Nov 20, 12:27 am, Tony_VBACoder
    > <> wrote:
    > > With ASP.NET 2.0 VB.NET, how do I:
    > >
    > > I have a multi-column (4 columns) DataList control on my WebForm that
    > > displays sports teams for our league. The data is grouped by Division Names
    > > where there are 4 teams per Division. When the data is displayed on the Web
    > > Page, it will be a 4x4 (4 columns by 4 rows) grid. What I need to be able to
    > > do is, add a separator row whenever the Division Name changes and display
    > > that Division name such that it spans across 4 columns.
    > >
    > > I have a stored procedure that sorts the data by Division name, so the data
    > > is already coming in sorted by Division. All I need to be able to do is
    > > detect when the Division name changes, and then add a new row to the DataList.
    > >
    > > I have done something similar using a GridView control and the "Protected
    > > Overrides Sub Render(ByVal writer As HtmlTextWriter)" event, but I can't seem
    > > to find any examples of how to do this with a DataList control.

    >
    >
    Tony_VBACoder, Nov 24, 2007
    #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. Nevyn Twyll
    Replies:
    8
    Views:
    1,845
  2. =?Utf-8?B?Tmlja3k=?=

    How to Add an new row in DataGrid programmatically?

    =?Utf-8?B?Tmlja3k=?=, Feb 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,039
    =?Utf-8?B?RG90TmV0SmVyb21l?=
    Feb 26, 2005
  3. Chris

    Add GridView Row Programmatically

    Chris, Apr 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    6,147
    Chris
    Apr 20, 2006
  4. H5N1
    Replies:
    0
    Views:
    2,698
  5. D
    Replies:
    0
    Views:
    197
Loading...

Share This Page