how to put a specific size to a column in a gridview

I have a gridview with these columns: Comment (255 char), user name(varchar 50), rating (int 1), date (yyyy-mm-dd). Now when this gridview is showing up it put the comment in one big cell. I will like the text to be wrap up on many lines (let say 50 chars).

Here is how I will like the gridview comes out :

Comment user name rating date

aaaaaaaaaaBBBBBBBBBBaaaaaaaaaaBBBBBBBBBBaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbb 4 2014-01-31 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccccccccccccccccccccc

Here is the code behind

    SqlConnection con = new 

    //======= Insert Query.

    string cmdText = "INSERT INTO Comments VALUES (@comment,@user,@rate, @date)";

    SqlCommand cmd = new SqlCommand(cmdText, con);

    //===== Adding parameters/Values.

    cmd.Parameters.AddWithValue("@comment", txtComment.Text);
    cmd.Parameters.AddWithValue("@user", txtSignature.Text);
    cmd.Parameters.AddWithValue("@rate", lstbxRating.Text);
    cmd.Parameters.AddWithValue("@date", DateTime.Now);

    if (con.State == ConnectionState.Closed)
    int nbrRecords = cmd.ExecuteNonQuery();


    if (nbrRecords >= 1)

Here is the .aspx

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        <asp:BoundField DataField="comment" HeaderText="comment" ReadOnly="True" 
             SortExpression="comment"  />
        <asp:BoundField DataField="user" HeaderText="user" ReadOnly="True" 
             SortExpression="usager" />
        <asp:BoundField DataField="rate" HeaderText="rate" ReadOnly="True" SortExpression="rate"
        <asp:BoundField DataField="date" HeaderText="date" ReadOnly="True" SortExpression="date" 


Set a fixed size to your cell, and then set the white-space to pre-wrap:

.className { 
   white-space: pre-wrap!important;      /* CSS3 */   
   white-space: -moz-pre-wrap!important; /* Firefox */    
   white-space: -pre-wrap!important;     /* Opera <7 */   
   white-space: -o-pre-wrap!important;   /* Opera 7 */    
   word-wrap: break-word!important;      /* IE */

(apply the class to your cell).

Here is what I did... just add ItemStyle-Width="" property... easy no ?

Here is the code in the .aspx

      <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
              <asp:BoundField DataField="comments" HeaderText="comments" ReadOnly="True" 
                   SortExpression="comments" ItemStyle-Width="1500" />
              <asp:BoundField DataField="userr" HeaderText="usager" ReadOnly="True" 
                   SortExpression="usager" />
              <asp:BoundField DataField="rating" HeaderText="rating" ReadOnly="True" 
                   SortExpression="cote" DataFormatString="{0:0/5}" />
              <asp:BoundField DataField="date" HeaderText="date" ReadOnly="True" 
                   SortExpression="date" DataFormatString="{0:MM-dd-yyyy}" />

Need Your Help

Hibernate ignore setting values on property with ManyToOne relationship

java spring hibernate spring-mvc many-to-one

I have a Java Spring MVC controller application. It uses hibernate 4 and spring 3. Using Bitronix transaction manager

Create a helper or something for haml with ruby on rails

ruby-on-rails ruby haml

I am using haml with my rails application and i have a question how the easiest way to insert this haml code into a html file: