How to display a literal/label in asp repeater control

Hi All,
I have this code snippet in aspx file

--------------------------------------------------------------------
<asp:repeater id="rptHouses" runat="server" OnItemDataBound="rptHouses_OnItemDataBound">
        <HeaderTemplate>
        <table>
        </HeaderTemplate>
            <ItemTemplate>
                <p>
                             
                    <table>
                   <tr> <td><strong><%# DataBinder.Eval(Container.DataItem, "name") %></strong><br /></td></tr>
                    <tr><td><%# DataBinder.Eval(Container.DataItem, "Address") %><br />
                    <%# DataBinder.Eval(Container.DataItem, "City") %>,
                    <%# DataBinder.Eval(Container.DataItem, "State") %>
                    <%# DataBinder.Eval(Container.DataItem, "zip") %><br /><br /></td></tr>
                  <tr id="trlocal" runat="server"><td> Local: <%# DataBinder.Eval(Container.DataItem, "local") %><br /></td></tr>
                  <tr id="trtollfree" runat="server"><td>Toll Free: <%# DataBinder.Eval(Container.DataItem, "tollfree") %><br /> </td></tr>
                  <tr id="trfax" runat="server"><td>Fax: <%# DataBinder.Eval(Container.DataItem, "fax") %><br /><br /></td></tr>
                   <tr><td> <%# DataBinder.Eval(Container.DataItem, "businesshours") %> </td></tr>
                   <tr id="trhtml" runat="server"><td><%#DataBinder.Eval(Container.DataItem, "html") %></td></tr>
                   
                 
                    </table>
              <%= ViewSpecificInventory.Text %>
               
                </p>
            </ItemTemplate>
            <FooterTemplate></table></FooterTemplate>
        </asp:repeater>
------------------------------------------------------------------------------

And I have this code snippet in code behind file

------------------------------------------------------------------------------
 protected void rptHouses_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item))
        {
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "local"))))
            {
                HtmlTableRow Trrow = (HtmlTableRow)e.Item.FindControl("trlocal");
                Trrow.Attributes.Add("style", "display:none");
            }
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "tollfree"))))
            {
                HtmlTableRow Trrow1 = (HtmlTableRow)e.Item.FindControl("trtollfree");
                Trrow1.Attributes.Add("style", "display:none");
            }
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "fax"))))
            {
                HtmlTableRow Trrow1 = (HtmlTableRow)e.Item.FindControl("trfax");
                Trrow1.Attributes.Add("style", "display:none");
            }
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "html"))))
            {
                HtmlTableRow Trrow1 = (HtmlTableRow)e.Item.FindControl("trhtml");
                Trrow1.Attributes.Add("style", "display:none");
            }
            if (Convert.ToString(DataBinder.Eval(e.Item.DataItem, "location_type_id")).Equals("1"))
            {
                ViewSpecificInventory.Text = "<p><a href=\"/heavy-truck-and-equipment/heavy-truck-part-search-aspx.aspx\">Search Inventory</a></p>";
            }
            else
                ViewSpecificInventory.Text = "<p><a href=\"/search-inventory.aspx\">Search Inventory</a></p>";
-------------------------------------------------------------------------------------------


I want to display ViewSpecificInventory which depends on location_type_id in the database just below every "html" in the repeater control table.

If I define ViewSpecificInventory as literal, I get an error that literal is already in use (since it is repeating). I can display the value of ViewSpecificInventrory (after checking if location_type_id is 1 or something else) in the table. But how do I put the value of ViewSpecificInventory in table then. I am sort of lost.

Thanks.
pratz09Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rajvjaCommented:
Hi,

   Instead of <%=ViewSpecificInventoryText%>, place a label.

Read that label in the code behind and update its text.
0
pratz09Author Commented:
That is the problem. When i put a label anywhere inside repeater control, it gives error that this label is already in use. May be because the code repeats ?
0
pratz09Author Commented:
I have put <asp:Label ID="ViewSpecificInventory" runat="server"></asp:Label>

in place of <%=ViewSpecificInventoryText%>,

And in code behind I do

 protected void rptHouses_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item))
        {
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "local"))))
            {
                HtmlTableRow Trrow = (HtmlTableRow)e.Item.FindControl("trlocal");
                Trrow.Attributes.Add("style", "display:none");
            }
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "tollfree"))))
            {
                HtmlTableRow Trrow1 = (HtmlTableRow)e.Item.FindControl("trtollfree");
                Trrow1.Attributes.Add("style", "display:none");
            }
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "fax"))))
            {
                HtmlTableRow Trrow1 = (HtmlTableRow)e.Item.FindControl("trfax");
                Trrow1.Attributes.Add("style", "display:none");
            }
            if (string.IsNullOrEmpty(Convert.ToString(DataBinder.Eval(e.Item.DataItem, "html"))))
            {
                HtmlTableRow Trrow1 = (HtmlTableRow)e.Item.FindControl("trhtml");
                Trrow1.Attributes.Add("style", "display:none");
            }
            if (Convert.ToString(DataBinder.Eval(e.Item.DataItem, "location_type_id")).Equals("1"))
           
                ViewSpecificInventory.Text = "<p><a href=\"/heavy-truck-and-equipment/heavy-truck-part-search-aspx.aspx\">Search Inventory</a></p>";
           
            else
                ViewSpecificInventory.Text = "<p><a href=\"/search-inventory.aspx\">Search Inventory</a></p>";

        }

    }


It says ViewSpecificInventory name does not exist in this context.
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

IgorNedCommented:
Just add FindControl :

Label ViewSpecificInventory = (Label)rptHouses.FindControl("ViewSpecificInventory");
if (Convert.ToString(DataBinder.Eval(e.Item.DataItem, "location_type_id")).Equals("1"))
      ViewSpecificInventory.Text = "<p><a href=\"/heavy-truck-and-equipment/heavy-truck-part-search-aspx.aspx\">Search Inventory</a></p>";
else
       ViewSpecificInventory.Text = "<p><a href=\"/search-inventory.aspx\">Search Inventory</a></p>";
0
pratz09Author Commented:
Now it throws System.NullReferenceException: Object reference not set to an instance of an object.

for assigning ViewSpecificInventory.Text = "..";
0
IgorNedCommented:
Sorry the actual assignment should look like this (tested):

Label ViewSpecificInventory = (Label)e.Item.FindControl("ViewSpecificInventory");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pratz09Author Commented:
That's right. I was going to post it. But yea, we have to use RepeatereventArg to find the asp control (label). It works fine now. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.