Solved

ASP.NET repeater giving me trouble

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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.…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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