对不起,如果帖子标题不清楚,我会尽量在这里解释一下。是否可以即时修改Databound内容?
我正在使用数据绑定到数据表的Web控件。数据的输出是这样的:
<asp:Repeater ID="RssRepeater" Visible="false" EnableViewState="false" runat="server">
<asp:literal ID="sb_description" Text='<%# DataBinder.Eval (Container.DataItem, "description") %>' EnableViewState="false" runat="server" />
''// Rest of structure...
</asp:Repeater>
我写的,从理论上讲,应该修剪传递的字符串到指定数量的单词的功能:
protected string CreateTeaser(string Post)
{
int wordLimit = 50;
System.Text.StringBuilder oSB = new System.Text.StringBuilder();
string[] splitBy = new string[] { " " };
string[] splitPost = Post.Split(splitBy,
System.StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i <= wordLimit - 1; i++)
{
oSB.Append(string.Format("{0}{1}", splitPost[i],
(i < wordLimit - 1) ? " " : ""));
}
oSB.Append(" ...");
return oSB.ToString();
}
我想这可憎的
<asp:literal ID="sb_description" Text='<%= CreateTeaser(%> <%# DataBinder.Eval (Container.DataItem, "description") %><%=); %>' EnableViewState="false" runat="server" />
但当然它没有工作。那么,Databinder.Eval(...)
这个函数是否可以在这个文字控件中使用?如果是这样,我该如何去做这件事?如果不是,我想要做什么替代?
谢谢!
谢谢,这让我走上了正轨:) – Anders 2009-07-02 16:45:47