Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I display data in grid view.

but some data is longer then space specified for that column.

if data is long then it represent as .....

what can i do for that?
Posted
Comments
[no name] 22-Feb-13 4:10am    
use text wrap for gridview cell.
piyush_dobariya 22-Feb-13 4:48am    
i don't want wrap data. But display as .... dotted line if data is longer then the column size.
Orcun Iyigun 22-Feb-13 4:11am    
Do you want to wrap the column data or do you want to change the column width corresponding to the data? What do you want to do?
piyush_dobariya 22-Feb-13 4:47am    
i don't want wrap the data or don't change the column width. if the statement is long(long then column size) then represent as ... dotted line
Shubh Agrahari 22-Feb-13 4:20am    
you want this in window application or ASP.Net...??

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.
C#
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);
}


Good luck,
OI
 
Share this answer
 
It's not that difficult. Have a look here: A multi-selection Drop Down List using a generic Abstract PopUp class[^] and see the FitTextToSpace method
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900