想要从包含2个或更多值的单个列中检索数据库中的数据

编程入门 行业动态 更新时间:2024-10-28 16:27:09
本文介绍了想要从包含2个或更多值的单个列中检索数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个数据库,我有SeeAlsoPageReference列,我用以下代码保存了价值:

String PageRefs = txt_SeeAlsoPageReference.Text; if (PageRefs.Contains( ;)) { String [] PageRefArray = PageRefs.Split(' ;'); for ( int i = 0 ; i < PageRefArray.Length; i ++) { seeAllpagereference + = PageRefArray [i] + < br />; } }

i保存数据库中的值,如: ef35988c-9a70-493d-a98a-0320989b1a42 ef35988c-9a70-493d-a98a-0320989b1a42 aspx:

< div id = SeeAlsoDiv > < asp:标签 ID = lbl_SeeAlso runat = server 文本 = 另请参阅 CssClass = lbl_seeAlso > < / asp:标签 > < br / > < asp:HyperLink ID = hyplnk_SeeAlso href = runat = server 文本 = > < / asp:HyperLink > < / div >

i使用的代码:

DataTable dt3 = DAL.OnlineHelp.PiiloHelp(Session [ pageRef]。ToString(),Session [ LanguageId] ToInt32())。 if (dt3.Rows.Count > 0 ) { string SeeAlsoPageRef = dt3.Rows [ 0 ] [ SeeAlsoPageReference]。ToString(); SeeAlsoPageRef = dt3.Rows [ 0 ] [ SeeAlsoPageReference]。ToString()。替换( & lt; , <); SeeAlsoPageRef = dt3.Rows [ 0 ] [ SeeAlsoPageReference]。ToString()。替换( & gt; , >); hyplnk_SeeAlso.Text = SeeAlsoPageRef; $ b}

使用上面的代码,它显示了值但有1个链接。 i当我从数据库中检索此值时需要: ef35988c- 9a70-493d-a98a-0320989b1a42 9487fe04-01e0-02cd-079f-c6be42224537 并且两者都充当不同的超链接,所以当我点击第一个链接时,它会转到该链接, 当我点击第二个链接时,它会转到另一个链接。 db列可能包含2个以上的值。 这是我在代码项目中的第一篇文章。请告诉我该怎么做。

解决方案

你需要2+ 超链接对象,而不仅仅是1.超链接只有一个链接( NavigateUrl )到一个地方,所以如果你需要多个链接,你需要多个超链接,并在它们之间拆分数据。 您可以为具有多个值的此字段创建 ListView 。它将有一个 TemplateColumn ,其中包含超链接。 类似于以下内容:

< asp:TemplateColumn > < ItemTemplate > < asp:HyperLink runat = server ID = hyplnk_SeeAlso NavigateUrl =' <% BindingExpressionGoesHere %> ' 文字 =' <% BindingExpressionGoesHere %> ' > < / asp:HyperLink > < / ItemTemplate > < / asp:TemplateColumn >

希望有所帮助。

i have a database , on that i have SeeAlsoPageReference column, i saved value on that with the below code:

String PageRefs = txt_SeeAlsoPageReference.Text; if (PageRefs.Contains(";")) { String[] PageRefArray = PageRefs.Split(';'); for (int i = 0; i < PageRefArray.Length; i++) { seeAllpagereference += PageRefArray[i] + "<br/>"; } }

i save the value in the database like: ef35988c-9a70-493d-a98a-0320989b1a42 ef35988c-9a70-493d-a98a-0320989b1a42 aspx:

<div id="SeeAlsoDiv"> <asp:Label ID="lbl_SeeAlso" runat="server" Text="See Also" CssClass="lbl_seeAlso"></asp:Label><br /> <asp:HyperLink ID="hyplnk_SeeAlso" href="" runat="server" Text=""></asp:HyperLink> </div>

i used the code:

DataTable dt3 = DAL.OnlineHelp.PiiloHelp(Session["pageRef"].ToString(), Session["LanguageId"].ToInt32()); if (dt3.Rows.Count > 0) { string SeeAlsoPageRef = dt3.Rows[0]["SeeAlsoPageReference"].ToString(); SeeAlsoPageRef = dt3.Rows[0]["SeeAlsoPageReference"].ToString().Replace("&lt;", "<"); SeeAlsoPageRef = dt3.Rows[0]["SeeAlsoPageReference"].ToString().Replace("&gt;", ">"); hyplnk_SeeAlso.Text = SeeAlsoPageRef; }

with the above code it shows both the value but with 1 link. i want when i retreive this value from database like: ef35988c-9a70-493d-a98a-0320989b1a42 9487fe04-01e0-02cd-079f-c6be42224537 and both act as a different hyperlink, so when i click on the 1st link it goes a/c to that link, and when i click on the second link it goes on another link. db column may contain more than 2 values. this is my first post in code project. please tell how i do this.

解决方案

You need 2+ Hyperlink objects, not just 1. A hyperlink only has one link (NavigateUrl) to one place, so if you need multiple links you need multiple hyperlinks, and split the data between them. You could create a ListView for this field with multiple values. It would have a TemplateColumn which contained a Hyperlink. Something along the lines of this:

<asp:TemplateColumn> <ItemTemplate> <asp:HyperLink runat="server" ID="hyplnk_SeeAlso" NavigateUrl='<% BindingExpressionGoesHere %>' Text='<% BindingExpressionGoesHere %>'></asp:HyperLink> </ItemTemplate> </asp:TemplateColumn>

Hope that helps.

更多推荐

想要从包含2个或更多值的单个列中检索数据库中的数据

本文发布于:2023-10-14 11:28:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1490943.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   更多   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!