Format text in DataGrid

xJessxrcs

New Member
Hi! I have a DataGrid that shows all the records in my database, but I don't want the DataGrid to show all the text in my memo-field. I want to be able to show say, 30 chars followed by "..."<BR>Does anyone have the solution to this?<BR>Thanksyou have to create a function/method that formats the text. <BR><BR>Try something like this:<BR><BR><itemTemplate><BR> <%# formatMemo(DataBinder.Eval(Container, "DataItem.Memo")%><BR></itemTemplate><BR><BR>code behind c#:<BR><BR>public string formatMemo(string memo)<BR>{<BR> //format your memo string<BR> if (memo.Length < 30)<BR> {<BR> return memo;<BR> }<BR> else<BR> {<BR> return memo.Substring(0,30) + "..."<BR> }<BR>}<BR>Pretty much the same in VB, use strLen and left/right instead of Substring and lenght.<BR><BR>I hope this workhi,<BR><BR>u can control the lenght in "ItemDataBound" event<BR>check for length and trim the length<BR><BR>Sub Item_Bound(sender As Object, e As DataGridItemEventArgs)<BR><BR>dim str as string=e.cells(4).text<BR>'check for the lenght trim tha ,agian u assign it to <BR>e.cells(4).text="<trimed string>"<BR><BR> End Sub 'Item_Bound <BR>hope this will solve ur problem<BR>regards<BR>yesu<BR>Hi. I can't get the text string I need. When I tried your example I got this error message: "'Cells' is not a member of 'System.Web.UI.WebControls.DataGridItemEventAr gs'" I've tried to find the answe in the documentation, but no luck so far..sorry for that,i missed "item" in that code<BR><BR>"e.Item.Cells(5).Text()" <BR>use this u will get string value<BR>regards<BR>yesu<BR><BR><BR>
 
Back
Top