only one line in datagrid cell
-
i have a column in datagrid that expose the company name....when the name of the company is long it is divided into multiple lines ...i want to force these lines to be one line and the remaining of the name is hide when the mouse over it, the remaining of the name appear
haitham
-
i have a column in datagrid that expose the company name....when the name of the company is long it is divided into multiple lines ...i want to force these lines to be one line and the remaining of the name is hide when the mouse over it, the remaining of the name appear
haitham
Hers a custom control you can use:
using System; using System.Web.UI.WebControls; namespace My.Controls{ public class TruncLabel :Label { public TruncLabel() : base (){} protected override void Render(System.Web.UI.HtmlTextWriter writer){ this.CssClass="fxS"; this.ToolTip = this.Text; base.Render(writer); } } }
Your stylesheet should then contain the following:.fxS { overflow:hidden; white-space:nowrap; overflow-clip:rect(auto, auto, auto, auto); }
The page containing the datagrid<%@ Register TagPrefix="mi" Namespace="My.Controls" Assembly="MyProjectOrSomething" %> . . asp:datagrid id="myDataGrid" runat="server" CssClass="grid" GridLines="None" AutoGenerateColumns="False"> Columns> asp:TemplateColumn HeaderText="Name" ItemStyle-VerticalAlign="Top"> ItemTemplate> mi:TruncLabel id="tlblName" Font-Bold="True" runat="server"> <%#DataBinder.Eval(Container.DataItem, "strCompanyName").ToString()%> mi:TruncLabel> ItemTemplate> asp:TemplateColumn> Columns>
-
Hers a custom control you can use:
using System; using System.Web.UI.WebControls; namespace My.Controls{ public class TruncLabel :Label { public TruncLabel() : base (){} protected override void Render(System.Web.UI.HtmlTextWriter writer){ this.CssClass="fxS"; this.ToolTip = this.Text; base.Render(writer); } } }
Your stylesheet should then contain the following:.fxS { overflow:hidden; white-space:nowrap; overflow-clip:rect(auto, auto, auto, auto); }
The page containing the datagrid<%@ Register TagPrefix="mi" Namespace="My.Controls" Assembly="MyProjectOrSomething" %> . . asp:datagrid id="myDataGrid" runat="server" CssClass="grid" GridLines="None" AutoGenerateColumns="False"> Columns> asp:TemplateColumn HeaderText="Name" ItemStyle-VerticalAlign="Top"> ItemTemplate> mi:TruncLabel id="tlblName" Font-Bold="True" runat="server"> <%#DataBinder.Eval(Container.DataItem, "strCompanyName").ToString()%> mi:TruncLabel> ItemTemplate> asp:TemplateColumn> Columns>
thanks for your reply but can`t we use the ordinary label and change cssclass and tooltip properties of this label?.. i will try it and tell u thanks again for your help....
haitham