Solved

ASP.NET repeater giving me trouble

Posted on 2009-03-31
5
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

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

Author Comment

by:smithdale87
ID: 24029959
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
ID: 24030080
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
ID: 24030274
Still getting the same error
0
 

Author Comment

by:smithdale87
ID: 24030897
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

707 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