This is a migrated thread and some comments may be shown as answers.

RadGrid max height

1 Answer 655 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 08 Dec 2009, 10:12 PM
Hi all,

Is there any way to set the maximum number of lines in each row (or maximum height of each row) in RadGrid, so if the content is shorter than the maximum, it will be fully displayed, but if the contect has more lines, all the lines beyond the maximum will be hidden.??

for example. if I define "maximum rows" =3

the following text:

This is a test: line 1
This is a test: line 2
This is a test: line 3
This is a test: line 4

will only display the top 3 line in the gird row.

Is there any way to do that?

Thanks,
feng

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 09 Dec 2009, 12:01 PM
Hi Joe,

Table cells cannot be prevented from expanding vertically, so setting ItemStyle-Height is of no use in your case. There are 2 ways to limit the visible content:

1. Subscribe to the RadGrid's ItemDataBound event and modify the cell text on the server.

2. Use a template column with some container with an overflow CSS style set (overflow:hidden or overflow:auto)


Below is a simple demo, which demonstrates both techniques. In addition, you may want to use browser tooltips or RadToolTip for the content, which is rendered, but not visible.

http://www.telerik.com/help/aspnet-ajax/grdtooltipsforgriditems.html

http://demos.telerik.com/aspnet-ajax/tooltip/examples/targetcontrolsandajax/defaultcs.aspx?product=grid


<%@ Page Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<script runat="server">
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem && !e.Item.IsInEditMode)
        {
            GridDataItem itm = e.Item as GridDataItem;
            itm["Column1"].Text = itm["Column1"].Text.Substring(0, 4);
        }
    }
     
</script>
 
<head runat="server">
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>RadControls for ASP.NET AJAX</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
 
<telerik:RadGrid
    ID="RadGrid1"
    runat="server"
    Width="700px"
    Skin="Office2007"
    AutoGenerateColumns="false"
    DataSourceID="XmlDataSource1"
    OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView TableLayout="Fixed">
        <Columns>
            <telerik:GridBoundColumn UniqueName="Column1" DataField="Column1" HeaderText="using ItemDataBound" />
            <telerik:GridTemplateColumn UniqueName="Column2" HeaderText="using scrollable container">
                <ItemTemplate>
                    <div style="height:57px;overflow:auto">
                        This is some text enclosed inside a scrollable container.
                        This is some text enclosed inside a scrollable container.
                        This is some text enclosed inside a scrollable container.
                        This is some text enclosed inside a scrollable container.
                        This is some text enclosed inside a scrollable container.
                        This is some text enclosed inside a scrollable container.
                    </div>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn UniqueName="Column2" HeaderText="using non-scrollable container">
                <ItemTemplate>
                    <div style="height:57px;overflow:hidden">
                        This is some text enclosed inside a container, which clips the content that does not fit.
                        This is some text enclosed inside a container, which clips the content that does not fit.
                        This is some text enclosed inside a container, which clips the content that does not fit.
                    </div>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
 
<asp:XmlDataSource ID="XmlDataSource1" runat="server">
<Data>
<nodes>
<node Column1="1 value" />
<node Column1="2 value" />
<node Column1="3 value" />
<node Column1="4 value" />
<node Column1="5 value" />
</nodes>
</Data>
</asp:XmlDataSource>
 
</form>
</body>
</html>



Sincerely yours,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or