[英]How do i manipulate a string/dataitem in my Listview?
这是我在列表视图中显示字符串的方式:
<%# Eval("Description")%>
这是获取listview数据的方法中的代码:
lstBlog.DataSource = blg;
lstBlog.DataBind();
我该如何操作“描述”字符串...即从字符串中获取任何前html标签,仅获得前50个字符/ ........
提前感谢
在aspx页面
<%# CutString(Eval("Description").ToString(),50) %>
在cs中
public string CutString(string value , int len)
{
// ....
}
在aspx页面中,您可以直接将字符串部分如下所示:
<%# Convert.ToString(Eval("Description")).Substring(0, 50) %>
“要么”
在aspx页面中,为ListView创建ItemDataBound事件
<asp:Label ID="lblDescription" runat="server" Text=""></asp:Label>
在后面的代码中,创建ItemDataBound
protected void lvData_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Blog blg = (Blog)e.Item.DataItem;
Label lblDescription = (Label)e.Item.FindControl("lblDescription");
lblDescription.Text = blg.Description.Substring(0, 50);
}
}
要剥离HTML标签,请参见此处: http : //www.dotnetperls.com/remove-html-tags
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.