Vinz' Blog

"Code, Beer and Music" ~ my way of being a programmer!
posts - 124, comments - 367, trackbacks - 0

My Links

News

Archives

Image Galleries

How to: Wrap the data of a Particular Column in GridView

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!


 

Print | posted on Sunday, May 03, 2009 6:10 PM |

Feedback

Gravatar

# re: How to: Wrap the data of a Particular Column in GridView

Your Code Helped me, Thank You!! For sharing this information.
7/21/2009 11:38 PM | Chandralekha.N.S
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: