Solved

ASP.NET repeater giving me trouble

Posted on 2009-03-31
5
168 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

15 Experts available now in Live!

Get 1:1 Help Now