Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to force a DataGrid to display only the first 20 cha
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires Web
Divers
Thread ID:
00764688
Message ID:
00764961
Vues:
18
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.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform