Asp.net sets the GridView adaptive column width without deformation, and the gridview column width
Because the number of columns of the dynamically bound GridView is not fixed, and there are too many columns, setting the fixed width of the GridView cannot meet the requirements. To solve this problem, we have sorted out two methods to achieve the effect of self-adapting the column width without deformation in the GridView.
// Set protected void gvObjectList_RowDataBound (object sender, GridViewRowEventArgs e) {if (e. row. rowType = DataControlRowType. dataRow | e. row. rowType = DataControlRowType. header) {// keep the column unchanged for (int I = 0; I <e. row. cells. count; I ++) {// Method 1: e. row. cells [I]. text = "& nbsp;" + e. row. cells [I]. text + "& nbsp;"; e. row. cells [I]. wrap = false; // Method 2: // e. row. cells [I]. text = "<nobr> & nbsp;" + e. row. cells [I]. text + "& nbsp; </nobr> ";}}}
Code Description:
Method 1: Set the automatic line feed attribute of cell to false.
Method 2: Use html tags to avoid line breaks. It is a space that allows a certain distance between the grid lines and the content inside to keep the appearance.
If you are interested, start it and see how it works.