我首先使用的值创建数据表,
DataTable dt = new DataTable("MyTable");
dt.Columns.Add(new DataColumn("Project ID", typeof(int)));
dt.Columns.Add(new DataColumn("Title", typeof(string)));
dt.Columns.Add(new DataColumn("HighwayCostScore", typeof(double)));
dt.Columns.Add(new DataColumn("BridgeCostScore", typeof(double)));
dt.Columns.Add(new DataColumn("HighwayComplexityScore", typeof(double)));
dt.Columns.Add(new DataColumn("BridgeComplexityScore", typeof(double)));
DataRow dr;
通过循环在特定列中添加值,然后添加到数据集“dset”
dt.Rows.Add(dr);
dset.Tables.Add(dt);
然后网格视图与dset绑定,
finalset.Tables.Add(dtt);
GridViewHcost.DataSource = dset;
每件事都很好但是Title字段有很大的价值所以我需要改变它的列宽但我不能尝试很多东西,比如,
DataGridViewColumn column = dataGridView.Columns[0];
column.Width = 60;
protected void GridViewHcost_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
TableCell cell = e.Row.Cells[1];
cell.Width = new Unit("200px");
for (int i = 0; i <= e.Row.Cells.Count - 1; i++)
{
if (i != 1)
{
TableCell cell2 = e.Row.Cells[i];
cell2.Width = new Unit("50px");
}
}
}
}
但这些对我不起作用
我很难改变这一栏“标题”的宽度???
希望得到你的建议
谢谢!
EDITED:
i have attached pic of grid in which i want to increase tile column with and to decrease the rest of column width
答案 0 :(得分:1)
在aspx页面中设置每列的宽度。 e.g
<HeaderStyle HorizontalAlign="Left" Width="50px" ></HeaderStyle>
<ItemStyle HorizontalAlign="Left" Width="50px"></ItemStyle>
<asp:BoundField HeaderText="abc" HeaderStyle-Width="120px" ControlStyle-Font-Bold="true"
ControlStyle-CssClass="MyText" DataField="BrandName">
<ControlStyle CssClass="MyText" Font-Bold="True"></ControlStyle>
</asp:BoundField>