Soulblade
Soulblade

Reputation: 71

How to limit the text of RadGrid column with option to view more content

I have a Radgrid with a column Product Description. The product description is very long and it obscures the view for the user.

Please see attached picture

Radgrid Product Description View: https://i.sstatic.net/uvi2X.jpg

How can I hide portion of the text where a see more content extends the hidden text.

Upvotes: 0

Views: 862

Answers (1)

Soulblade
Soulblade

Reputation: 71

The solution is as the follows:

  • Instead of using 'GridBoundColumn' use 'GridTemplateColumn' see code below:

Designer View:

<telerik:GridTemplateColumn DataField="Product_Description" HeaderText="Product Description" UniqueName="Product_Description">
  <ItemTemplate>
    <asp:Label ID="Product_DescriptionLabel" runat="server" Text='<%# TrimDescription(Eval("Product_Description") as string) %>'></asp:Label>
  </ItemTemplate>
</telerik:GridTemplateColumn>

Code View:

protected string TrimDescription(string description) { if (!string.IsNullOrEmpty(description) && description.Length > 200) { return string.Concat(description.Substring(0, 200), "..."); } return description; }

The page is only used to view a summary of the requested tables.

See screenshot: Product Description

Upvotes: 1

Related Questions