数据库字段 Nname,Nfiles,Ndate 其中 Nfiles = "1.doc|2.txt|3.excel"我先将个字段读出绑定到datalist中,
Nname和Ndate都没问题,Nfiles显示也没问题,但不是我想要的我想处理一下 Nfiles 变成以下再绑定
<a href = 'files/1.doc'>1.doc</a>
<a href = 'files/2.txt'>2.txt</a>
<a href = 'files/3.excel'>3.excel</a>请问要如何处理呢!
Nname和Ndate都没问题,Nfiles显示也没问题,但不是我想要的我想处理一下 Nfiles 变成以下再绑定
<a href = 'files/1.doc'>1.doc</a>
<a href = 'files/2.txt'>2.txt</a>
<a href = 'files/3.excel'>3.excel</a>请问要如何处理呢!
{
string[] arrstr = str.Split('|');
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arrstr.Length; i++)
{
sb.Append("<a href = 'files/"+arrstr[i]+"'>"+arrstr[i]+"</a>");
} return sb.ToString(); }
1、再sql语句中拼出<a href = 'files/1.doc'>1.doc</a>这个链接
2、用DataList的ItemDataBound事件
但是读出来后和在aspx页面 <%# Eval("Nfiles")%>这里我不知道怎么处理好!这个才是重点
ArrayList array = new ArrayList();
if (Honors.Length >= 1)
{
for (int i = 0; i < Honors.Length; i++)
{
ShopsLibrary modelShop = new ShopsLibrary();
modelShop.Honor = Honors[i];
array.Add(modelShop);
}
}
repHonor.DataSource = array;
repHonor.DataBind();这样就可以了
public string GetValue(string s )
{
StringBuilder sb = new StringBuilder();
foreach(string s in str.Split('|'))
{
sb.Append("<a href = 'files/"+s+"'>"+s+"</a>");
}
return sb.ToString();
}