Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a form in which I have used datalist to get data from database...In form i want that data should have link..i have following data
Rajasthan
punjab
bengal
south india

there should be link and respective page should be open
i tried following code

XML
<asp:DataList ID="DataList2" runat="server" DataSourceID="SqlDataSource2" RepeatColumns="5" RepeatDirection="Horizontal"  HorizontalAlign="Center">

      <ItemTemplate>

        <div style="margin-left: 60px; margin-top: 3px; margin-bottom: 3px; margin-right: 10px;">
  <span class="bluearrow">&raquo;</span>  </div>


 <asp:HyperLink ID="HyperLink2" runat="server">
              <asp:Label ID="categoryLabel" runat="server" Text='<%# Eval("category") %>' />

              <br />
              <br />
              <br />
</asp:HyperLink>
          </ItemTemplate>
      </asp:DataList>


i couldnt get any link over there..please support me on this
regards
Posted

use
C#
<asp:hyperlink id="HyperLink2" runat="server" > <%#Eval("category")%> </asp:hyperlink>
 
Share this answer
 
v2
Try this one mate,
ASP.NET
<asp:datalist id="DataList2" runat="server" datasourceid="SqlDataSource2" repeatcolumns="5" repeatdirection="Horizontal" horizontalalign="Center" xmlns:asp="#unknown">
   <itemtemplate>
     <asp:hyperlink id="HyperLink1" runat="server" navigateurl="<%# Eval("Url") %>" text="<%# Eval("Name") %>" />
    </itemtemplate>
</asp:datalist>
 
Share this answer
 
Comments
Member 13274154 30-Jun-17 6:09am    
how to send parameters with navigateurl?
XML
you should edit the item template of the DataList and put an ASP HyperLink inside, and you use data binding to assign the NavigateUrl to such control.

<pre lang="xml">&lt;asp:DataList ID=&quot;listSearchResults&quot; Border=&quot;1&quot; BorderColor=&quot;Black&quot;
    RepeatDirect=&quot;Horizontal&quot; RepeatColumns=&quot;5&quot; runat=&quot;server&quot; &gt;
    &lt;ItemTemplate&gt;

     &lt;asp:HyperLink ID=&quot;HyperLink1&quot; runat=&quot;server&quot; NavigateUrl=&#39;&lt;%# Eval(&quot;Url&quot;) %&gt;&#39; Text=&#39;&lt;%# Eval(&quot;Name&quot;) %&gt;&#39; /&gt;

    &lt;/ItemTemplate&gt;
&lt;/asp:DataList&gt;</pre>



another approach is to use ASP:LinkButton and assign CommandName and CommandArgument properties to that control.
 
Share this answer
 
try as shown in the following example:
ASP.NET
<asp:datalist onitemcommand="itemcommand" id="DataList1" runat="server" datakeyfield="name" width="600px" xmlns:asp="#unknown">
DataSourceID="SqlDataSource1" RepeatColumns="3" HorizontalAlign="Center">
<itemtemplate>
<asp:linkbutton id="lnk" cssclass="Name" commandname="lnk1" runat="server" text="xyz"></asp:linkbutton><br />
</asp:label>
</itemtemplate>
</asp:datalist>

In code behind file i have used follows:--
C#
protected void itemcommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("lnk1"))
{
Response.Redirect("Acer.aspx");
}
}
 
Share this answer
 
v2

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



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