?
Solved

ASP.NET repeater giving me trouble

Posted on 2009-03-31
5
Medium Priority
?
173 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

771 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