I put a gridview in a asp.net page.I connect to access and get data.Data can be shown in grid without any error.But I want to resize the Gridview header so that contents(data) fit in gridview cells in a line without wrap. I test wrap propertt and set Wrap
to "false".but I does not work.I write a function to compute data length in any cell and set cell width based on it.is there any simple way?my friend said to (win-app datagrid) has a "Autofit" propery but web-app grid view hasn't this property.
is there any simple way to Autofit cells in grid view?
please leave your ideas and answers even they are simple or funny.
You could add the "white-space:nowrap" style to each GridView cell in the RowDataBound event. There is perhaps a better way, but I know at least this works.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("style", "white-space:nowrap;");
}
}
Marked as answer by mohsenAmani on Jun 18, 2009 04:14 AM
mohsenAmani
Member
92 Points
58 Posts
Problem with autofit cells in gridview asp.net
Jun 02, 2009 06:26 PM|LINK
hello all
I put a gridview in a asp.net page.I connect to access and get data.Data can be shown in grid without any error.But I want to resize the Gridview header so that contents(data) fit in gridview cells in a line without wrap. I test wrap propertt and set Wrap to "false".but I does not work.I write a function to compute data length in any cell and set cell width based on it.is there any simple way?my friend said to (win-app datagrid) has a "Autofit" propery but web-app grid view hasn't this property.
is there any simple way to Autofit cells in grid view?
please leave your ideas and answers even they are simple or funny.
thank you
RatheeshC
Contributor
5652 Points
1198 Posts
Re: Problem with autofit cells in gridview asp.net
Jun 02, 2009 07:57 PM|LINK
Hi,
Try to apply this style "white-space: nowrap;" in the cell..
Thanks
Ratheesh
Ratheesh
Please mark it as answer if it resolves your issue.
nmadd
Member
48 Points
34 Posts
Re: Problem with autofit cells in gridview asp.net
Jun 02, 2009 07:59 PM|LINK
You could add the "white-space:nowrap" style to each GridView cell in the RowDataBound event. There is perhaps a better way, but I know at least this works.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { for (int i = 0; i < e.Row.Cells.Count; i++) { e.Row.Cells[i].Attributes.Add("style", "white-space:nowrap;"); } }muhibd85
Member
5 Points
19 Posts
Re: Problem with autofit cells in gridview asp.net
Jul 06, 2010 10:45 PM|LINK
i. This really works. I found it after searching alot for the solution. Thanks. H