Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable text wrap in asp.net gridview

The output is like this:

MyNameIsJohnSmithAnd
Imaperson

What I want is to display it in only one line

MyNameIsJohnSmithAndImaperson

My Aspx gridview code is:

<asp:GridView ID="GridView1" runat="server" BackColor="LightGoldenrodYellow" 
    BorderColor="Tan" BorderWidth="1px" CellPadding="5" Font-Names="Calibri" 
    Font-Size="Medium" Font-Underline="False" ForeColor="Black">
    <RowStyle Wrap="False"/>
    <EmptyDataRowStyle Wrap="False"/>
    <FooterStyle BackColor="Tan" BorderColor="Black" BorderStyle="Solid" Wrap="False"/>
    <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
        HorizontalAlign="Center" Wrap="False" />
    <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" Wrap="False"/>
    <HeaderStyle BackColor="Tan" BorderStyle="Solid" Font-Bold="True" Wrap="False"/>
    <EditRowStyle Wrap="False"/>
    <AlternatingRowStyle BackColor="PaleGoldenrod" Wrap="False"/>
</asp:GridView>

I disabled all the wrap property to false in gridview. but the text still wraps.

like image 374
user1954418 Avatar asked Feb 28 '13 02:02

user1954418


3 Answers

You have to set the gridview's individual column's word wrap to False as well.

<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" >
            <ItemStyle Wrap="False" />
            </asp:BoundField>
like image 59
RMuesi Avatar answered Nov 14 '22 20:11

RMuesi


Try adding this event to your gridview.

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    for (int i = 0; i < e.Row.Cells.Count; i++)
    {
        e.Row.Cells[i].Attributes.Add("style", "white-space: nowrap;");
    }
}

Here is the reference.

like image 21
Freddie Fabregas Avatar answered Nov 14 '22 20:11

Freddie Fabregas


Very simple in .Net Select your grid view (as in Design mode) in property window and follow this RowStyle -->Font -->>Wrap=False

Thats done

like image 3
user3578419 Avatar answered Nov 14 '22 19:11

user3578419