用“...”代替超长字符串
看了清清月儿写的代码,但是遇到一个问题,如果我对超链接列使用这个代码的话,用“...”代替超长字符串是实现了,但是超链接变成一个字符串,没法链接了,怎么办?for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
DataRowView mydrv;
string gIntro;
if (GridView1.PageIndex == 0)
{
mydrv = myds.Tables["飞狐工作室"].DefaultView[i];//表名
gIntro = Convert.ToString(mydrv["家庭住址"]);//所要处理的字段
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
}
else
{
mydrv = myds.Tables["飞狐工作室"].DefaultView[i + (5 * GridView1.PageIndex)];
gIntro = Convert.ToString(mydrv["家庭住址"]);
GridView1.Rows[i].Cells[3].Text = SubStr(gIntro, 2);
}
}
public string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr = sNewStr + "...";
return sNewStr;
} --------------------编程问答-------------------- <%# (Eval("标题").ToString()).Length>20)?
(Eval("标题").ToString()).Substring(0,19)+"...":(Eval("标题").ToString()) %>
你把这些贴在你页面要绑定的字符串上就好了的说 --------------------编程问答-------------------- 我没看清就发贴了,先顶一下再说了!哈哈 --------------------编程问答-------------------- 哈,突然发现我这个也能用的哈 --------------------编程问答-------------------- aspx中代码:
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="htmlload" DataTextField="title" />
<asp:BoundField DataField="publishtime" DataFormatString="{0:d}" HtmlEncode="False" />
</Columns>
aspx.cs中代码:
protected void datainit()
{
string sql = "select * from news";
ds = dscl.Getds1(sql);
this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.GridView1.DataBind();
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
DataRowView mydrv;
string gIntro;
mydrv = ds.Tables[0].DefaultView[i + (10 * GridView1.PageIndex)];
gIntro = Convert.ToString(mydrv["title"]);
GridView1.Rows[i].Cells[0].Text = SubStr(gIntro, 2);
}
}
public string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr = sNewStr + "...";
return sNewStr;
} --------------------编程问答-------------------- 后台
public string GetShortTitle(string str_title, int str_lenth)
{
if (str_title.Length > str_lenth)
{
return str_title.Substring(0, str_lenth) + "...";
}
else
{
return str_title;
}
}
前台
<%# GetShortTitle(Eval("name").ToString(),10) %> --------------------编程问答-------------------- 不用超连接,就用普通的模版列,用标签
<asp:Label id="lbl" text='<%# SubStr(Eval("data").ToString(),10)%>' ...> --------------------编程问答-------------------- 如果是用超链接呢
<asp:HyperLinkField DataNavigateUrlFields="htmlload" DataTextField="title" />
<asp:BoundField DataField="publishtime" DataFormatString="{0:d}" HtmlEncode="False" />
--------------------编程问答-------------------- ddddddddd --------------------编程问答-------------------- 四楼正解!! --------------------编程问答-------------------- 为什么不直接在数据库中优化呢? --------------------编程问答-------------------- 如果要精确,只能是人工设置一个摘要,其实摘要里一般是不需要格式化的,直接显示文本即可。(过滤所有的HTML标签)
补充:.NET技术 , ASP.NET