Hi Robert,
To limit the string, change the DataGrid column to a Template column. Then the databinding for the field needs to call a code-behind function. Here is some sample code:
<ItemTemplate>
<asp:Label runat="server" Text='< %# formatString((string)(DataBinder.Eval(Container, "DataItem.ProductName"))) % >'>
</asp:Label>
</ItemTemplate>
In the code-behind:
public string formatString(string s)
{
string results;
if (s.Length >= 20)
{
results = s.Substring(0,20);
}
else
{
results = s;
}
return results;
}
>hello!
>
>how can i force a datagrid to display only the first eg. 20 characters?
>i would need this for some sort of online faqs in my web app. in the datagrid all the faqs are listed an only a small part of the description should be displayed. when the user clicks on the topic of each listing the full description is displayed beneath.
>
>another question:
>same case as above but i want to format a date-field - how to do this?
>
>TIA
-----------------------------------------
Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.comwww.prenia.comWeblog: blogs.prenia.com/cathi