RE: Sections in repeater
- From: Jakob Lithner <jaklithn@xxxxxxxxxxxxxxx>
- Date: Fri, 10 Nov 2006 04:46:02 -0800
I am not sure I got your idea, to do the hiding AFTER the data binding ....?
I find it more natural to keep doing it in the ItemDataBound event, where I
have all the information needed.
The biggest problem was to find a way to hide/collapse the section.
In my initial example I did the line breaks by using <DIV>-tags, but the
problem with them is that they will occupy space even when they have no
InnerHTML. And I was not able to get hold of them to change attributes from
code. Is it possible?
Next I tried TextBox control. It is easy to get hold of from code and I was
able to hide border and set ReadOnly. So I had clean VB-code, but I was not
able to get rid of all visual padding .... It kept looking strange, despite
my efforts.
So my final solution was to switch to Label-controls. Setting "display:
block" will give the Label a similar block behaviour as the previous
<DIV>-tag. By changing the CSS-style I was able to hide it from code
depending on data values.
I am not perfectly happy about dragging CSS-layout into the code, but it
works fine and looks nice!
Suggestion on improvements are welcome.
CSS-template
============================
..gadgetSection
{
display: block;
font-weight: bold;
margin-top: 10px;
}
..gadgetLine
{
display: block;
}
ASP-code
============================
<asp:Repeater ID="repLista" runat="server">
<ItemTemplate>
<asp:Label ID="lblSection" CssClass="gadgetSection"
runat="server"></asp:Label>
<asp:Label ID="lblLine" CssClass="gadgetLine"
runat="server"></asp:Label>
</ItemTemplate>
</asp:Repeater>
Code-behind
============================
Protected Sub repLista_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
repLista.ItemDataBound
Dim lblSection As Label
Dim lblLine As Label
Dim dv As System.Data.DataRowView
Dim c As dsNorthwind.CustomersRow
Static lastCity As String = ""
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
'Grab the data
dv = DirectCast(e.Item.DataItem, System.Data.DataRowView)
c = CType(dv.Row, dsNorthwind.CustomersRow)
'Find the controls
lblSection = DirectCast(e.Item.FindControl("lblSection"),
Label)
lblLine = DirectCast(e.Item.FindControl("lblLine"), Label)
'Display data
lblLine.Text = c.CompanyName
If lastCity = c.City Then
lblSection.Style.Add("display", "none")
Else
lblSection.Text = c.City
End If
'Remember value for comparison
lastCity = c.City
End Select
End Sub
.
- Follow-Ups:
- RE: Sections in repeater
- From: Walter Wang [MSFT]
- RE: Sections in repeater
- References:
- RE: Sections in repeater
- From: Walter Wang [MSFT]
- RE: Sections in repeater
- From: Walter Wang [MSFT]
- RE: Sections in repeater
- Prev by Date: Re: Accessing User Control used inside the Master Page
- Next by Date: Static menu item background image anchor corona
- Previous by thread: RE: Sections in repeater
- Next by thread: RE: Sections in repeater
- Index(es):
Relevant Pages
|