私のGridView:
<asp:GridView ID="GridView1" runat="server"
OnRowDataBound="GridView1_RowDataBound"
AutoGenerateColumns="true"
DataKeyNames="Role_id">
</asp:GridView>
コードビハインド:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//e.Row.Cells[2].Width = 120; // isn't working....
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Width = new Unit(120); // isn't working....
TableCell cell = e.Row.Cells[2];
cell.HorizontalAlign = HorizontalAlign.Right; //**** does work!
cell.BackColor = Color.LightGray; //**** does work!
//cell.Width = 120; // isn't working....
//e.Row.Cells[2].Width = new Unit("120px") ; // isn't working....
//e.Row.Cells[2].CssClass = "myGV_Cell_Width"; // isn't working....
}
}
GridView が正常に設定されました。列の配置と背景色は設定できますが、幅は設定でき
ないことに注意してください。
出回っている多くのソリューションを試しましたが、どれもうまくいきませんでした。
列のサイズは常に最長のコンテンツに変更されます。
果たして出来るのか…?