[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET repeater giving me trouble

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 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