Dynamically bound GridView because the number of columns is not fixed, and there are too many columns (the blogger does this project has 150 or so fields), so set the GridView fixed width can not meet the demand. Two methods are arranged to achieve the effect of the GridView Adaptive column width without distortion.
. aspx.cs
Copy Code code as follows:
Set in an event that is bound by the row data of the GridView
protected void Gvobjectlist_rowdatabound (object sender, GridViewRowEventArgs e)
{
if (E.row.rowtype = = Datacontrolrowtype.datarow | | e.row.rowtype = = datacontrolrowtype.header)
{
Keep Column not deformed
for (int i = 0; i < E.row.cells.count; i++)
{
Method One:
E.row.cells[i]. Text = "" + e.row.cells[i]. Text + "";
E.row.cells[i]. Wrap = false;
Method Two:
E.row.cells[i]. Text = "<nobr>" + e.row.cells[i]. Text + "</nobr>";
}
}
}
Method one is to set the cell's automatic line-wrapping property to False, method two is to use HTML tag way to achieve no change line; is a space, you can make the grid line and the contents of the inside to maintain a certain distance to keep beautiful.