Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2006, 01:46 PM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid - Column width problems - word wrapping

Hello,

I have problems with a datagrid's column width. When I have a long text the column no wrap and extend the width of my columns. Therefore my datagrid goes off the screen. How I control the width of my columns in datagrid? I used <itemstyle Wrap="true"></itemstyle> or I set the width of each column to an specific width but seems not to be working.
Any ideas....

Thanks

 
Old October 3rd, 2006, 11:51 AM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<asp:DataGrid ID="MyRepeater" runat="server"
     BackColor="#eeeeee" Width="85%"
     HorizontalAlign="Center"
     Font-Name="Verdana" CellPadding="4"
     Font-Size="10pt" AutoGenerateColumns="False">
    <HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="True" HorizontalAlign="Center" />
    <AlternatingItemStyle BackColor="White"/>
<columns>
<asp:BoundColumn DataField="Fecha" HeaderText="Fecha" SortExpression = "Fecha" ItemStyle-Wrap="False"></asp:BoundColumn>
<asp:BoundColumn DataField="Observ" HeaderText="Observaciones" SortExpression = "Observ"></asp:BoundColumn>
<asp:BoundColumn DataField="Estado" HeaderText="Estado" SortExpression = "Estado" ItemStyle-Wrap="False"></asp:BoundColumn>
<asp:BoundColumn DataField="Autor" HeaderText="Autor" SortExpression = "Autor" ItemStyle-Wrap="False"></asp:BoundColumn>
   </columns>
</asp:DataGrid>

The problem I have is that Observ goes widther than should be... It won't wrap my text.

How can I accomplish that?

Gracias


 
Old October 3rd, 2006, 12:22 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Mi amigo/amiga,
  I copied your datagrid code exactly as you have it here and pasted it into a VS form; what i did was executed a simple SELECT statement that selected a long line of text into each column of your datagrid.

Result:
With the way your code is set up, the datagrid blew off the side of the page since the other 3 columns have wrap set to false, but, the Observ column wrapped just fine. I adjusted this so that all columns wrapped and the datagrid was displayed over 85% of the screen just as it should be.

Here is my code: (.aspx page)

            <asp:DataGrid ID="dg" runat="server" BackColor="#eeeeee" Width="85%" HorizontalAlign="Center"
                Font-Name="Verdana" CellPadding="4" Font-Size="10pt" AutoGenerateColumns="False">
                <AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
                <HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="Black"></HeaderStyle>
                <Columns>
                    <asp:BoundColumn DataField="a" SortExpression="Fecha" HeaderText="Fecha">
                        <ItemStyle Wrap="True"></ItemStyle>
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="b" SortExpression="Observ" HeaderText="Observaciones">
                    <ItemStyle Wrap="true"></ItemStyle>
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="c" SortExpression="Estado" HeaderText="Estado">
                        <ItemStyle Wrap="True"></ItemStyle>
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="d" SortExpression="Autor" HeaderText="Autor">
                        <ItemStyle Wrap="True"></ItemStyle>
                    </asp:BoundColumn>
                </Columns>
            </asp:DataGrid>
.vb page:
        Dim sqlcmd As String
        sqlcmd = "SELECT 'this is a very long string so long in fact that i want the text to wrap the datagrid does this work out or does it fail like the p2p member says it does?' as a, 'this is a very long string so long in fact that i want the text to wrap the datagrid does this work out or does it fail like the p2p member says it does?' as b, 'this is a very long string so long in fact that i want the text to wrap the datagrid does this work out or does it fail like the p2p member says it does?' as c, 'this is a very long string so long in fact that i want the text to wrap the datagrid does this work out or does it fail like the p2p member says it does?' as d"
        dt = da.getDataTable(sqlcmd)

        dg.DataSource = dt
        dg.DataBind()

DT is a datatable, the object da is just my custom class that retrieves data from a database.

hth.

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old October 3rd, 2006, 12:57 PM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Amigo,

I got the same result as before.It won't wrap the observ data. When I use <ItemStyle Wrap="true"></ItemStyle>for the four Datafields (Fecha,Observ,Estado and Autor) will wrap correctly the following: Fecha,Estado and Autor but not Observ. It will blow off the screen the Observ data... How I can control the Observ data to wrap correctly.

Gracias por tu ayuda.(Thanks for your help)



 
Old October 5th, 2006, 02:24 PM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got to work Thanks

 
Old October 5th, 2006, 02:33 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Sorry I didnt get back to you, but what did the resolution end up being?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old October 5th, 2006, 03:49 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

cp75:
What did u do to get it to work...inquiring minds would like to know.
 
Old October 12th, 2006, 08:51 AM
Authorized User
 
Join Date: Aug 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I played around with of the table. I set all the ItemStyle to wrap true.<ItemStyle Wrap="true"></ItemStyle>. Otherwise, If I set just one itemstyle to wrap won't work.

 
Old July 31st, 2008, 04:30 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi machu..just try this in ur code behind

MyGrid.Attributes.Add("style", "table-layout:fixed");

then in HTML View of the gird if you have Label to Display the item in tiemdatbound give style="word-.... : break;"

*.... pls check that, i forgot that , then give column width it will work fine

mathew m mathew - malayalee mankan
<
Smile – It brings a difference...
Dance – Who knows when u won’t be able to?
Cry - Holding those emotions is bad for u…
Laugh – Whatz the point in hiding happiness?
Apologize – You dont want to lose frnds…
Live – coz life is everything u have…!!!!!!!!!!
 />








Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid Column Width Problem demivolt ASP.NET 1.0 and 1.1 Professional 1 July 22nd, 2005 09:05 AM
Setting Column width in Datagrid anita General .NET 2 April 13th, 2005 02:25 AM
DataGrid column width johanyu VS.NET 2002/2003 0 October 30th, 2004 05:29 AM
Word wrapping in Datagrid Astalder ASP.NET 1.0 and 1.1 Basics 1 May 5th, 2004 08:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.