susanthosh
susanthosh

Reputation: 450

How can I wrap header text in Gridview?

Hi I am writing some code to display some records in Grid view. I am using Firefox as my Default browser. I wish to wrap a header text. but Firefox is not supporting the wrap property. How can I achieve this?

Upvotes: 0

Views: 17311

Answers (4)

user4789177
user4789177

Reputation: 1

HeaderStyle-Wrap="true" or ItemStyle-Wrap="true" cannot wrap header text. Only HeaderStyle-Width = something, say "120px", then it will force the header text to wrap

Upvotes: -1

susanthosh
susanthosh

Reputation: 450

Apply a style sheet to the header template. In the style add white-space:normal. It will wrap the header text automatically

For eg, class name is mystyle in stylesheet:

.mystyle
{
  white-space:normal;
}

In the aspx page, include Headerstyle-CssClass="myStyle".

Upvotes: 2

solairaja
solairaja

Reputation: 964

Use the Div tag to place the Header text. -- before that convert the BOUNDEDFIELD to the TEMPLATEFIELD

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
                    <Columns>
                        <asp:TemplateField HeaderText="UserID" SortExpression="UserID">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("UserID") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("UserID") %>'></asp:Label>
                            </ItemTemplate>
                            <HeaderTemplate>   <div STYLE="word-wrap: break-word">Your HEADER</div>
                           </HeaderTemplate>
                        </asp:TemplateField></asp:GridView>

Upvotes: 4

Himadri
Himadri

Reputation: 8876

Set attribute HeaderStyle-Wrap="true" in <asp:TemplateField> tag

Please mark as answer if it helps.

Upvotes: 3

Related Questions