Solved

ASP.NET repeater giving me trouble

Posted on 2009-03-31
5
167 Views
Last Modified: 2013-11-07
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.



<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;

    }

Open in new window

0
Comment
Question by:smithdale87
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
NazoUK earned 500 total points
Comment Utility
You haven't marked the td with runat="server"
0
 

Author Comment

by:smithdale87
Comment Utility
thanks for the quick response

I edited the code ( see below ). Unfortunately, I still get the same error.

Any other idaes?


<td ID="litPropertyCell" runat="server">

Open in new window

0
 
LVL 15

Expert Comment

by:NazoUK
Comment Utility
Try putting the code inside your itemdatabound routine inside this if:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType== ListItemType.AlternatingItem)
{
...
}
0
 

Author Comment

by:smithdale87
Comment Utility
Still getting the same error
0
 

Author Comment

by:smithdale87
Comment Utility
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


<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>

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now