欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Asp.net簡單代碼設(shè)置GridView自適應(yīng)列寬不變形實(shí)現(xiàn)思路與代碼

 更新時(shí)間:2013年01月16日 12:06:15   作者:  
動(dòng)態(tài)綁定的GridView由于列數(shù)不固定,而列又太多(博主做的這個(gè)項(xiàng)目有150個(gè)左右的字段),這樣設(shè)置GridView固定寬度就不能滿足需求了
動(dòng)態(tài)綁定的GridView由于列數(shù)不固定,而列又太多(博主做的這個(gè)項(xiàng)目有150個(gè)左右的字段),這樣設(shè)置GridView固定寬度就不能滿足需求了。為此整理了兩種方法來達(dá)到GridView自適應(yīng)列寬不變形的效果。
.aspx.cs
復(fù)制代碼 代碼如下:

//在GridView的行數(shù)據(jù)綁定完的事件中設(shè)置
protected void gvObjectList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
//保持列不變形
for (int i = 0; i < e.Row.Cells.Count; i++)
{
//方法一:
e.Row.Cells[i].Text = "&nbsp;" + e.Row.Cells[i].Text + "&nbsp;";
e.Row.Cells[i].Wrap = false;
//方法二:
//e.Row.Cells[i].Text = "<nobr>&nbsp;" + e.Row.Cells[i].Text + "&nbsp;</nobr>";
}
}
}

方法一是設(shè)置cell的自動(dòng)換行屬性為false,方法二是用html標(biāo)記的方式實(shí)現(xiàn)不換行;&nbsp;就是一個(gè)空格,可以讓網(wǎng)格線和里面的內(nèi)容留有一定的距離保持美觀。

相關(guān)文章

最新評(píng)論