如何使用C#.net从数据列表中获取超链接文本值 [英] How to get the hyperlink text value from datalist using C#.net
问题描述
大家好,
1)当我需要获取超链接文本值时(< code> Text =''& lt;%#Eval(& quot; file_name& quot;)%& gt;<//code>)我将单击超链接.
2)当我单击Linkbutton时,我需要获取链接按钮命令名称.
以下是我的数据列表代码.
< pre lang ="HTML"> < asp:DataList ID =& quot; datamum& quot; runat =&服务器" DataKeyField =& quot; Policy_id& quot;
Font-Bold =& quot; False& quot; Font-Italic =&"False& quot; Font-Overline =& quot; False& quot;
Font-Strikeout =&"False& quot; Font-Underline =&"False& quot; HorizontalAlign =&左&"
onitemdatabound =&"datamum_ItemDataBound&"字体大小=&小& amp;". onitemcommand =& quot; datamum_ItemCommand& quot;& gt;
& lt; ItemTemplate& gt;
< asp:标签ID =& quot; lblid& amp; quot; runat =&服务器" Text =''& lt;%#Eval(& quot; Policy_id& quot;)%& gt;''Visible =&"false& quot;&</asp:Label& amp;</asp:Label& ; gt;
< asp:标签ID =& quot; lbl& quot; runat =&服务器"文字=&"*&" ForeColor =& quot;棕色& gt;</asp:Label& gt;
& lt; asp:Hyperlink ID =&"hyfile&" runat =&服务器" Text =''& lt;%#Eval(& quot; file_name& quot;)%& gt;''NavigateUrl =& ##& quot; & lt;/asp:Hyperlink& gt;
< asp:面板ID =& quot; panid& amp; quot; runat =&服务器"样式=&"display:none;& gt;
< asp:DataList ID =& quot; Datasub& quot; runat =& quot;服务器& gt;
& lt; ItemTemplate& gt;
< asp:标签ID =& quot; lbl& quot; runat =&服务器"文字=&"*&" ForeColor =&蓝色". & lt;/asp:Label& gt;
& lt; asp:LinkButton ID =&"Inkid&" runat =&服务器" Text =''& lt;%#Eval(& quot; file_name& quot;)%& gt;''CommandName =& quot; Display& quot;& lt;/asp:LinkButton& amp; ; gt;
& lt;/ItemTemplate& gt;
& lt//asp:DataList& gt;
& lt//asp:Panel& gt;
& lt;/ItemTemplate& gt;
& lt//asp:DataList& gt;
</pre>
在此先感谢
Sucharitha
Hi All,
1) I need to get the hyperlink text value( <code>Text=''<%#Eval("file_name")%>''</code> ) when I will click on hyperlink.
2) I need to get the link button command name when i will click on Linkbutton.
Below is my Datalist code.
<pre lang="HTML"> <asp:DataList ID="datamum" runat="server" DataKeyField="Policy_id"
Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left"
onitemdatabound="datamum_ItemDataBound" Font-Size="Smaller" onitemcommand="datamum_ItemCommand">
<ItemTemplate>
<asp:Label ID="lblid" runat="server" Text=''<%# Eval("Policy_id")%>'' Visible="false"></asp:Label>
<asp:Label ID="lbl" runat="server" Text="*" ForeColor="Brown"></asp:Label>
<asp:Hyperlink ID="hyfile" runat="server" Text=''<%#Eval("file_name")%>'' NavigateUrl="#" ></asp:Hyperlink>
<asp:Panel ID="panid" runat="server" Style="display:none;">
<asp:DataList ID="Datasub" runat="server">
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text="*" ForeColor="Blue" ></asp:Label>
<asp:LinkButton ID="lnkid" runat="server" Text=''<%#Eval("file_name")%>'' CommandName="Display"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
</pre>
Thanks in Advance
Sucharitha
推荐答案
在Item_Command事件上尝试此操作
try this on Item_Command Event
LinkButton lnkbtn = (LinkButton)(e.CommandSource);
string lnkbtnText = lnkbtn.Text;
string CommandNAme = e.CommandName; // or lnkbtn.CommandName
希望这会有所帮助.
hope this helps..
这篇关于如何使用C#.net从数据列表中获取超链接文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!