如何在数据列表中使用超链接 [英] how to use hyperlink in datalist
本文介绍了如何在数据列表中使用超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个表单,在该表单中,我使用了数据列表从数据库中获取数据...在表单中,我希望数据应该具有链接..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">»</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"><asp:DataList ID="listSearchResults" Border="1" BorderColor="Black"
RepeatDirect="Horizontal" RepeatColumns="5" runat="server" >
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Name") %>' />
</ItemTemplate>
</asp:DataList></pre>
另一种方法是使用ASP:LinkButton并将CommandName和CommandArgument属性分配给该控件.
another approach is to use ASP:LinkButton and assign CommandName and CommandArgument properties to that control.
这篇关于如何在数据列表中使用超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文