Conditional Row in Repeater

W

Wayne Wengert

I am using VB with ASP.NET and I have a repeater control which displays a
list of records from a dataset. The records are ordered by ZIP code. I want
to insert an extra row containing the name of the current state (with a
different background color) when the value of the "State" field changes.
Based on some information I found via Google I am trying to include that
conditional row within a Panel control and then use the Visible property to
enable it when the value of State changes. Portions of my page and code are
below. When I run this I am getting an error that "Object reference not set
to an instance of an object" on the line:

Panel1.Visible = True

Any suggestions or advice appreciated

Wayne


=========== ItemBound Function ===============
Protected Sub NewClassRow(ByVal sender As Object, ByVal e As
RepeaterItemEventArgs)

If e.Item.ItemType = ListItemType.Item Or _

e.Item.ItemType = ListItemType.AlternatingItem Then

Dim dbr As System.Data.Common.DbDataRecord = CType(e.Item.DataItem,
System.Data.Common.DbDataRecord)

If Not (dbr("State")) = laststate Then

Panel1.Visible = True

laststate = dbr("State")

End If

End If

End Sub


======== portion of repeater control ======================
<ItemTemplate>
<asp:panel id="Panel1" visible =False runat="server">
<tr id="newclass" bgcolor="#ffff66" runat="server" height="0">
<td id="newclasscol" runat="server" colspan="8" align="center"
height="0">newstate</td>
</tr>
</asp:panel>
<tr>
<td><%# DataBinder.Eval(Container,"DataItem.FullName") %></td>
<td align="center"><%# DataBinder.Eval(Container,"DataItem.Group")
%></td>
<td align="center"><%# DataBinder.Eval(Container,"DataItem.City")
%></td>
<td align="center"><%# DataBinder.Eval(Container,"DataItem.State")
%></td>
<td>
<asp:HyperLink id="Hyperlink1" runat="server" NavigateUrl= '<%#
DataBinder.Eval(Container.DataItem,"WebSite") %>' Text= '<%#
DataBinder.Eval(Container, "DataItem.WebSite") %> '>
</asp:HyperLink>
</td>
</tr>
</ItemTemplate>
 
L

Lachlan James

Because the Panel is inside the repeater you will need to
get a reference to it by calling e.Item.FindControl()
before setting its value.
 
W

Wayne Wengert

Thank you - I'll try that.

Wayne

Lachlan James said:
Because the Panel is inside the repeater you will need to
get a reference to it by calling e.Item.FindControl()
before setting its value.
 
W

Wayne Wengert

I converted that code to get a reference but I get the same error? The
segment of code I changed is now as follows:

Dim p1 As Panel

If Not (dbr("State")) = laststate Then

p1 = CType(e.Item.FindControl("Panel1"), Panel)

p1.Visible = True

laststate = dbr("State")

End If



Wayne
 
W

Wayne Wengert

It was my error! The suggestion works fine. In testing it I had only created
a "Panel" for the ItemTemplate and not the AlternateItemTemplate - it failed
when it hit that!

Wayne
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top