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: ,,,