Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I tried to Show data using repeater in asp.net , I am facing a problem with hyperlink in repeater
The First li tag that is working Fine
ASP.NET
 <asp:Repeater ID="Repeater1" runat="server">
 <ItemTemplate>
	<li class="subMenu open"><a href ="../../../../Index.aspx?id=<%# Eval("Id")%>"><%#((Name_Repeater)Container.DataItem).Name %></a>

and   Hyperlink in 2nd li Tag is not working 

<HeaderTemplate>     
 <ul>
     </HeaderTemplate>
 <li><a href ='../../../../Index.aspx?id=<%# Eval("Id_Sub")%>'><%#((Name_Repeater)Container.DataItem).Subname %></a></li>
<FooterTemplate>
</ul>
    </FooterTemplate>
 </li>
         </ItemTemplate>
 </asp:Repeater> 


%#((Name_Repeater)Container.DataItem).Subname its show me the data , but the hyperlink is not working .


Aspx.cs Code
C#
DataTable dt;
      Category Category_Class = new Category();
      Category_Class.retrieve_category_by_all(ref Connection_String, out dt);
      List<Name_Repeater> Repeater = new List<Name_Repeater>();

      for (int a = 0; a < dt.Rows.Count; a++)
      {
          Name_Repeater qq = new Name_Repeater();

          string Category_Name = Convert.ToString(dt.Rows[a]["category_name"]);
          Category_id = Convert.ToByte(dt.Rows[a]["category_id"]);
        DataTable dt2;
      Subcategory Sub_Class = new Subcategory();
      Sub_Class.retrieve_Subcategory_by_Category_Id(ref Connection_String, ref Category_id, out dt2);

      string Sub_Cate_Name = "";
      for (int x = 0; x < dt2.Rows.Count; x++)
      {
          Sub_Category_id = Convert.ToByte(dt2.Rows[x]["subcategory_id"]);

          Sub_Cate_Name = Sub_Cate_Name + Convert.ToString(dt2.Rows[x]["subcategory_name"] + "<br>");
          qq.Nag_Url = "../../../../../../../Index.aspx?Cat_Id=" + Sub_Category_id;
     }
      qq.Id_Sub =  Sub_Category_id;
      qq.Name = Category_Name;

      qq.Subname = Sub_Cate_Name;
      qq.Id = Category_id;
    //  qq.Id_Sub = Sub_Category_id;
          Repeater.Add(qq);
      }
      Repeater1.DataSource = Repeater;
      Repeater1.DataBind();
Posted
Updated 4-May-15 21:31pm
v3
Comments
Can you please check the rendered HTML of that link to see what is the href?
Gurpreet Arora Malhotra 5-May-15 2:43am    
Suppose there is to values that repeater Contains , when i click on 1st one its highlights both
What do you mean by highlight? If there is no data on Repeater, then it should not show, right? Then how come you are able to see HyperLink when you don't have any data. It is confusing. Please explain more.
Gurpreet Arora Malhotra 5-May-15 3:04am    
there are two item in li tag , 1st one contain id 1 and 2nd one contain id 2 , when i click on 1st one its also highlight 2nd one
When you click, it should redirect to the URL. What you exactly mean by highlighting?

1 solution

This assumes simple list. If you're trying to do subitems then you have to add new repeater within the item (see below)

ASP.NET
<asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
<headertemplate>
<ul>
</ul></headertemplate>
 <itemtemplate>
	<li class="subMenu open"><a href="../../../../Index.aspx?id=<%# Eval(" id=")%>"><![CDATA[<%#((Name_Repeater)Container.DataItem).Name %></a>
 
<footertemplate>

    </footertemplate>
</li></itemtemplate></asp:repeater> 




Subitems - this will create subitems in first-level item, but it will still select whole list unless it is hidden until hovered / clicked
ASP.NET
<asp:repeater id="Repeater1" runat="server" xmlns:asp="#unknown">
    <headertemplate>
        <ul>
    </ul></headertemplate>
     <itemtemplate>
	<li class="subMenu open"><a href="../../../../Index.aspx?id=<%# Eval(" id=")%>"><![CDATA[<%#((Name_Repeater)Container.DataItem).Name %></a>

    <asp:repeater id="innerRepeater" runat="server">
        <headertemplate>     
             <ul>
         </ul></headertemplate>
        <itemtemplate>
             <li><a href="../../../../Index.aspx?id=<%# Eval("Id_Sub")%>"><![CDATA[<%#((Name_Repeater)Container.DataItem).Subname %></a></li>
        </itemtemplate>
        <footertemplate>
            
        </footertemplate>
     </asp:repeater>
     </li>
             </itemtemplate>
<footertemplate>
</ul>
    </footertemplate>
 </asp:repeater> 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900