如何在数据列表中使用超链接 [英] how to use hyperlink in datalist

查看:113
本文介绍了如何在数据列表中使用超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表单,在该表单中,我使用了数据列表从数据库中获取数据...在表单中,我希望数据应该具有链接..i具有以下数据
拉贾斯坦邦
旁遮普语
孟加拉国
南印度

应该有链接,并且相应的页面应该打开
我尝试了以下代码

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

<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

推荐答案

使用
<asp:hyperlink id="HyperLink2" runat="server" > <%#Eval("category")%> </asp:hyperlink>


尝试这个伴侣,
Try this one mate,
<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>


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>




另一种方法是使用ASP:LinkBut​​ton并将CommandName和CommandArgument属性分配给该控件.




another approach is to use ASP:LinkButton and assign CommandName and CommandArgument properties to that control.


这篇关于如何在数据列表中使用超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆