Visual Studio .NET - how to show only the first 30 characters in gridview column???[SOLVED]

Asked By Kenichi Jensen on 08-Aug-07 02:07 PM
I have a sql column with 2000 chracters.

At the moment, my gridview column shows all the characters.

Is there and option under gridview task -> edit column, where i can set
it to show only 30 charcaters or the first 10 words????

In the RowDataBound eventhandler, - Peter Bromberg replied to Kenichi Jensen on 08-Aug-07 06:56 AM

you can gain access to the individual Cell and trim the text content before the Grid completes rendering. RowDataBound fires for each row as the Grid is databound.

This is my solution - Kenichi Jensen replied to Peter Bromberg on 08-Aug-07 02:16 PM

This is what i did.

<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='
<%# Eval("Description").ToString().Length>30 ?
(Eval("Description") as string).Substring(0,30):
Eval("Description")%> '
>
</asp:Label>
</ItemTemplate>

And this works - so thanks you for showing me the ways of
the use of substrings :)

Substring - Navaneeth KN replied to Kenichi Jensen on 08-Aug-07 09:03 AM

Hi

You can use substring in your SQL query and fetch only 30 characters