0

我首先创建具有价值的数据表,

  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;

一切都很好,但标题字段的值很大,所以我需要改变它的列宽,但我不能尝试很多事情,比如,

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
4

1 回答 1

1

设置 aspx 页面中每一列的宽度。例如

<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>
于 2013-06-10T12:18:06.290 回答