smithdale87
asked on
ASP.NET repeater giving me trouble
I have an repeater that fills in cells in a table ( see below ).
For some reason, when I try and find my table cell control with ID "litPropertyCell", I always get a null value.
Is there something simple I'm doing wrong??
Thanks in advance.
For some reason, when I try and find my table cell control with ID "litPropertyCell", I always get a null value.
Is there something simple I'm doing wrong??
Thanks in advance.
<tr>
<asp:Repeater runat="server" ID="repProperties" OnItemDataBound="repProperties_ItemDataBound"
EnableViewState="true">
<ItemTemplate>
<td ID="litPropertyCell">
<asp:Literal ID="litProperty" runat="server"></asp:Literal>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
<%--- CodeBehind ---- %>
protected void repProperties_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
XmlNode node = e.Item.DataItem as XmlNode;
Literal litProperty = e.Item.FindControl("litProperty") as Literal;
HtmlTableCell cell = e.Item.FindControl("litPropertyCell") as HtmlTableCell;
if (cell == null) throw new Exception("LitPropertyCell is NULL!");
cell.BgColor = "Red";
litProperty.Text = node.InnerText;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try putting the code inside your itemdatabound routine inside this if:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType== ListItemType.AlternatingIt em)
{
...
}
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType== ListItemType.AlternatingIt
{
...
}
ASKER
Still getting the same error
ASKER
Figured it out.
I had an outer repeater that had an itemTemplate and AlternatingItemTemplate. The ItemTemplate was posted above. It was missing the "runat='server'". I failed to realize that the Alternating template also needed the same thing.
Again thanks for your help
I had an outer repeater that had an itemTemplate and AlternatingItemTemplate. The ItemTemplate was posted above. It was missing the "runat='server'". I failed to realize that the Alternating template also needed the same thing.
Again thanks for your help
<AlternatingItemTemplate>
<tr>
<asp:Repeater runat="server" ID="repProperties" OnItemDataBound="repProperties_ItemDataBound"
EnableViewState="true">
<ItemTemplate>
<td ID="litPropertyCell" runat="server">
<asp:Literal ID="litProperty" runat="server"></asp:Literal>
</td>
</ItemTemplate>
</asp:Repeater>
</tr>
</AlternatingItemTemplate>
ASKER
I edited the code ( see below ). Unfortunately, I still get the same error.
Any other idaes?
Open in new window