想要从包含2个或更多值的单个列中检索数据库中的数据 [英] want to retreive data from database from single column that contain 2 or more values
问题描述
我有一个数据库,我有SeeAlsoPageReference列,我用以下代码保存了价值:
< span class =code-sdkkeyword> 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 = < span class =code-keyword> 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
,其中包含超链接
。
类似于以下内容:
< < span class =code-leadattribute> asp:TemplateColumn >
< ItemTemplate >
< asp:HyperLink runat < span class =code-keyword> = 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("<", "<");
SeeAlsoPageRef = dt3.Rows[0]["SeeAlsoPageReference"].ToString().Replace(">", ">");
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 aListView
for this field with multiple values. It would have aTemplateColumn
which contained aHyperlink
.
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个或更多值的单个列中检索数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!