use a reapeter to display data, but sometimes the data is to big开发者_开发技巧 to be displayed in a cell. Can I use a method to allow the reapter to display the first 100 characters of a string and after that a hyperlink to display next page? any help is welcome!
You don't have the implementation details of your code, so this is a shot in the dark. If you are binding an object, create a new property that takes the first 100 characters of the information you want displayed:
class Foo
{
public String PropertyData {get;set;} //your real data;
public String DisplayData //bind the reader to this property instead.
{
get
{
return PropertyData.substring
(0, (PropertyData.Length >= 100) ? 100 : PropertyData.Length);
}
}
}
You can have the property return anything you want, this is just an example of how to get it to display only 100 characters.
You can leave this logic in the view:
<asp:Label runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "your_text_field").ToString().Substring(0, Math.Min(100, DataBinder.Eval(Container.DataItem, "your_text_field").ToString().Length %>' />
<asp:Hyperlink runat="server" Test='<%# Eval("your_text_field") %>'
Visible='<%# Eval("your_text_field").ToString().Length > 100 %>' />
精彩评论