你可以在.aspx中对他调整也可以在属性里设置,给一段代码参考一下好了:
<asp:BoundColumn DataField="yhm" ReadOnly="True" HeaderText="用户名"> <ItemStyle Width="120px"></ItemStyle></asp:BoundColumn>
<asp:BoundColumn DataField="zsxm" ReadOnly="True" HeaderText="真实姓名"> <ItemStyle Width="200px"></ItemStyle></asp:BoundColumn>
<asp:BoundColumn DataField="xb" ReadOnly="True" HeaderText="性别"></asp:BoundColumn> <asp:BoundColumn DataField="dzyj" ReadOnly="True" HeaderText="电子邮件"></asp:BoundColumn>

解决方案 »

  1.   

    我是用在C#的窗口中不是用在ASP.net中呀
      

  2.   

    windows 组件中是吧?设置PreferredColumnWidth
    和PreferredRowHeight的值,就能调整datagrid的列宽。
      

  3.   

    或我根本不要用DefaultView 来做,那我应该怎么做呢,能给个示范代码吗???
      

  4.   

    DataGrid每行的宽度:
    <ItemStyle HorizontalAlign="Center" Height="26px"></ItemStyle>
      

  5.   

    同意houlinghouling(新玲) 
      

  6.   

    看看,或许有帮助
    public static void AutoSizeTable(DataGrid dataGrid1,string tableName)
    {
    int numCols = ((DataTable) dataGrid1.DataSource).Columns.Count;
        for(int i = 0; i < numCols; ++i)
       {
              float width = 0;
    int numRows = ((DataTable) dataGrid1.DataSource).Rows.Count;
    Graphics g = Graphics.FromHwnd(dataGrid1.Handle);
    StringFormat sf = new StringFormat(StringFormat.GenericTypographic);
    SizeF size;
    for(int j = 0; j < numRows; ++ j)
    {
        size = g.MeasureString(dataGrid1[j,i].ToString(), dataGrid1.Font, 500, sf);
    if(size.Width > width)
    width = size.Width;
    }
    g.Dispose();
    dataGrid1.TableStyles[tablename].GridColumnStyles[i].Width = (int) width;
    }

    }
      

  7.   

    我现在实现了,我现在想我怎么把我的标题居中???
    BsClass getCustInfo = new BsClass();
    DataGridTableStyle ts1 = new DataGridTableStyle(); myDS = getCustInfo.GetCustInfo(0); dgCustInfo.SetDataBinding(myDS, "T_CustInfo");

    ts1.MappingName = "T_CustInfo"; DataGridTextBoxColumn myCol1 = new DataGridTextBoxColumn();

    myCol1.Alignment = HorizontalAlignment.Left;
    myCol1.HeaderText = "客户序号";//它要居中怎么做
    myCol1.MappingName = "ID";
    myCol1.Width = 70;
    ts1.GridColumnStyles.Add(myCol1); dgCustInfo.TableStyles.Add(ts1);