Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

One of the member at the http://forums.asp.net ask if how to wrap the data in the GridView Control. See this thread (http://forums.asp.net/t/1417574.aspx). I decided to post the solution that I was provided in that thread as a reference for all who needs a solution for the same issue.

Here’s the code block below: 

   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
   {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
        }
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //just changed the index of columns and the value of Unit based on your requirements
        this.GridView1.Columns[0].ItemStyle.Width = new Unit(100);
    }

As you can see, we just add an attribute to a particular column in the GridView and set the style “word-break:break-all;word-wrap:break-word"” and at RowCreated event of GridView we set the Width of the column that we need to wrap. 

That’s it! Hope you will find this post useful!

Technorati Tags: ,,,
Posted on Sunday, May 3, 2009 6:10 PM ASP.NET , C# , Tips&Tricks , GridView | Back to top


Comments on this post: How to: Wrap the data of a Particular Column in GridView

# re: How to: Wrap the data of a Particular Column in GridView
Requesting Gravatar...
Your Code Helped me, Thank You!! For sharing this information.
Left by Chandralekha.N.S on Jul 21, 2009 11:38 PM

# re: How to: Wrap the data of a Particular Column in GridView
Requesting Gravatar...
Thnks ? It word the code. but it gives me error when i paste code in rowcreated .index was out of range.

but i comment on line use only rowdatabound. it works fine.
Left by shrishail on Aug 22, 2011 4:46 PM

# re: How to: Wrap the data of a Particular Column in GridView
Requesting Gravatar...
Thanks.......This article is useful for me.....
Very Good Article............
Left by Niranjan poddar on Jun 14, 2012 4:26 PM

# re: How to: Wrap the data of a Particular Column in GridView
Requesting Gravatar...
finally i did bcoz of this..
Left by anand on Feb 12, 2013 7:34 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net