RE: Sections in repeater



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
.



Relevant Pages

  • Re: Multiple Column Table db results
    ... > How can I display my db results in a multi-column table? ... CSV file and do a Mail Merge with a Label document in MS-Word. ... Dim aSTR() ... Set objRST = Nothing ...
    (microsoft.public.inetserver.asp.db)
  • Re: Oracle SP question
    ... you can create a datarow based on a specific row in the dataset ... Dim ds As New DataSet ... Dim lbl As Label ... > I can display everything in the grid, but i want only 2 things to display ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Formatting number with two decimal places
    ... > I need to have a value display in a label with two decimal places; ... dim d as decimal ... dim s as string ...
    (microsoft.public.dotnet.languages.vb)
  • dynamic datagrids and allowsorting
    ... I'm trying to write a generalized report that just takes some SQL as a parameter and then dynamically creates datagrids to display the information. ... Dim newPanel As Panel = New Panel ... Dim lblTitle As Label = New Label ... Dim dgGen As DataGrid = New DataGrid ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: SQL access from Cobol Test
    ... Dim oWrite As System.IO.StreamWriter ... Dim workline As String ... 000380 01 NEW-GENERIC-REC. ... 000810 DISPLAY "INVALID READ FROM IMPORT TEXT FILE". ...
    (comp.lang.cobol)