DataList: How to create a separator that spans across all items

R

robnhood00

I have a datalist that repeats horizontally by 3. I'm trying to create
a header that will be dynamically displayed based on criteria. Let's
say we have 3 groups (A, B, C). I want it to do this:

---THIS IS A GROUP------
--------- --------- ---------
Item1 Item2 Item3
--------- --------- ---------

---------
Item4
---------

---THIS IS B GROUP------
--------- --------- ---------
Item1 Item2 Item3
--------- --------- ---------

---THIS IS C GROUP------
--------- ---------
Item1 Item2
--------- ---------

Any Ideas?
 
R

robnhood00

Did you ever find a way to do this? I have the exact same problem.

I had to work around this. I used three datalists and three tables. I
used a data apapter and then created manual filters on the
ItemDataBound. Here's the example:
<!--HTML CODE-->
<html>
<head><style type=text/css>
.hidden {display:none;}
</style>
</head>
<body>
<!--A GROUP-->
<asp:Table ID="tblA" Runat=server Visible=False Width=100%>
<asp:TableRow><asp:TableCell
Width=100%><b>A-GROUP</b></asp:TableCell></asp:TableRow></asp:Table>

<asp:DataList id="dlA" runat="server" RepeatColumns="4"
RepeatDirection="Horizontal">
<itemtemplate>
<asp:label id="lblGroupLetter" runat=server text='<%#
Container.DataItem("groupletter")%>' Visible=False />
<!-- CODE HERE-->

</itemtemplate>
</datalist>

<!--B GROUP-->
<asp:Table ID="tblB" Runat=server Visible=False Width=100%>
<asp:TableRow><asp:TableCell
Width=100%><b>B-GROUP</b></asp:TableCell></asp:TableRow></asp:Table>


<asp:DataList id="dlC" runat="server" RepeatColumns="4"
RepeatDirection="Horizontal">
<itemtemplate>
<asp:label id="lblGroupLetter" runat=server text='<%#
Container.DataItem("groupletter")%>' Visible=False />
<!-- CODE HERE-->

</itemtemplate>
</datalist>

<!--C GROUP-->
<asp:Table ID="tblC" Runat=server Visible=False Width=100%>
<asp:TableRow><asp:TableCell
Width=100%><b>C-GROUP</b></asp:TableCell></asp:TableRow></asp:Table>

<asp:DataList id="dlC" runat="server" RepeatColumns="4"
RepeatDirection="Horizontal">
<itemtemplate>
<asp:label id="lblGroupLetter" runat=server text='<%#
Container.DataItem("groupletter")%>' Visible=False />
<!-- CODE HERE-->

</itemtemplate>
</datalist>
</body>
</html>

<!--CODE BEHIND-->

'Get the data and bind it to all datalists
Dim adapter As SqlDataAdapter
Dim dt As New DataTable

cmd = New SqlCommand("qryGroups", c)
cmd.CommandType = CommandType.StoredProcedure
c.Open()

adapter = New SqlDataAdapter(cmd)
adapter.Fill(ds)

dlA.DataSource = ds.Tables(0)
dlA.DataBind()
dlB.DataSource = ds.Tables(0)
dlB.DataBind()
dlC.DataSource = ds.Tables(0)
dlC.DataBind()

'''''The following needs to exist for dlA & dlB, but they would all be
the same except for the groupletter filter.
Private Sub dlC_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlC.ItemDataBound
Dim groupletter As String

groupletter = CType(e.Item.FindControl("lblGroupLetter"),
Label).Text

If groupletter = "C" Then
dlC.Visible = True
tblC.Visible = True
Else
'Otherwise, clear the result
e.Item.CssClass = "hidden"
e.Item.Visible = False
e.Item.Controls.Clear()
End If
End Sub
 

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,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top