プログラムでasp.netのグリッドビューの列幅を設定する必要があります。** 自動生成された列 (つまり、AutogenerateColumns = "true")。
私は次のことを試しました;
protected void gv_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Width = Unit.Pixel(200);
}
しかし、役に立たない。
これは私GridView1
のaspxファイルです
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
Font-Size="Small" Width="800px" OnRowDataBound="GridView1_RowDataBound" >
<Columns>
<asp:CommandField SelectText="Seç" ShowSelectButton="True"/>
</Columns>
</asp:GridView>
これは、分離コードで GridView の列幅をプログラムで設定する場所です。実際にはセルの幅を設定することですが、列幅を制御するので、これは方法ですAutogeneratedColumns="True"
。これGridView.RowDataBound
は、データ行がデータにバインドされている場合に発生するためです。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[1].Width = 1;
e.Row.Cells[0].Width = 1;
e.Row.Cells[4].Width = 75;
e.Row.Cells[5].Width = 1;
}