Click here to Skip to main content
13,045,387 members (79,837 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a datagrid with some columns. One of it has a big width. At runtime I see the grid with a scrollbar and I can scroll left an right to see the whole grid.
I like to have that the grid has no scrollbar and each row is wrapped in a new line.
Is this somehow possible?
Posted 26-Feb-13 4:51am
Sandeep Mewara 26-Feb-13 11:20am
Have fixed width of the columns as per need to avoid scroll. By default contents should get wrapped, if not, put wrapping for the text.
Sergey Alexandrovich Kryukov 26-Feb-13 14:24pm
Right. Believe or not, I answered the question, please see.
Sergey Alexandrovich Kryukov 26-Feb-13 14:17pm
Wrapped row? Not wrapped cell content?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I am pretty much sure that none of the grid views can do it: it's beyond the nature of such controls.

All you can do is developing of your own custom control, but I don't advices it, it would strongly defeat the purpose of the grid view and would greatly confuse the users, including yourself. Just imagine it's look. It only seems to you that you "like to have". Draw it on paper, screen, or in your imagination, and you will quickly see that you won't like it at all. Better think on the design of narrower grid and perhaps some kind of "drill down", on click, context menu or somehow.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can wrap the text in grid.
You have to follow the below steps: 

1. GridView width should be in precentage (Width="100%")
2. In the same way you have to give column width (ItemStyle-Width="10%" HeaderStyle-Width="10%")
3. Set ItemStyle-Wrap="true" for wrapping the text
4. Sum of all cilumns width must be equal to 100%

<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False"
        GridLines="Vertical" Width="100%">
            <asp:TemplateField HeaderText="Remarks" ItemStyle-Wrap="true" ItemStyle-Width="80%" HeaderStyle-Width="10%">
                    <asp:Label ID="lblRemarks" runat="server" Text='<%# Bind("REMARKS") %>'></asp:Label>
            <asp:TemplateField HeaderText="Customer" ItemStyle-Width="10%" HeaderStyle-Width="10%">
                    <asp:Label ID="lblCustomerName" runat="server" Text='<%# Bind("CUSTOMERNAME") %>'></asp:Label>
            <asp:TemplateField HeaderText="Status" ItemStyle-Width="10%" HeaderStyle-Width="6%">
                    <asp:Label ID="lblSts" runat="server" Text='<%# Bind("Status") %>'></asp:Label>

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Thanks for your answers.
The idea with wrapping the text I don't like it because of the row height.
Either I have a fixed row height three times higher than normal to show all contents or
I have auto row height then I have a bumpy view depending if description column is wrapped.

This example shows what I like to have:


 Pos  Quantity  Unitprice  Unit  Discount  PO Number Total 
 1 3 5.00 Pc 50% 4512345678  7.50
 2 2 2.00 Pc 10% 4587654321  3.60
Lollypop sweet sour and cherry curry hot style taste

I will try to realize it by duplicate each row, make DataGridCells alternating visible or not
and group rows by Pos column.
Any criticism and suggestion are welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100