可以在绑定后修改
this.grdTest.Columns[1].HeaderText="";
this.grdTest.Columns[2].Visible=false;
属性应该很多

解决方案 »

  1.   

    DataView dv = new DataView(_dsContacts.Tables["Contact"]);
      dv.Sort = _sSort;
      dgContacts.DataSource = dv;
      dgContacts.DataBind();
    }
      

  2.   

    手动建表 把要显示的字段添加的表中 再通过设置datagrid.datasource和datagrid.datamember绑定
      

  3.   

    DataGrid的AutoGenerateColumns设为false
    在aspx文件中加入类似的代码:
    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 224px; POSITION: absolute; TOP: 104px" runat="server" AutoGenerateColumns="False">
    <Columns>
        <asp:BoundColumn HeaderText="姓名" DataField="Name"></asp:BoundColumn>
    </Columns>
    </asp:DataGrid>
    1.DataField就是你的数据表里面的实际字段名称.
    2.把你想显示的字段都用上面的方法写出来,没写的就不会显示
      

  4.   

    不行啊~~~
    没有这个属性的啊
    this.grdTest.Columns[1].HeaderText="";
      

  5.   

    用属性生成器吧,右单击DataGrid,属性生成器里设置列
      

  6.   

    如果是Web的就用Reapter吧! :)
      

  7.   

    呵呵~~各位谢谢了~~我找到了~~
    There are several ways to hide a column:1) You can use your DataSet's ColumnMapping property to hide a column. 
     
         // Creating connection and command sting 
     
         string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb"; 
     
         string sqlStr = "SELECT * FROM Employees"; 
     
         // Create connection object 
     
         OleDbConnection conn = new OleDbConnection(conStr); 
     
         // Create data adapter object 
     
         OleDbDataAdapter da = new OleDbDataAdapter(sqlStr,conn); 
      
         // Create a dataset object and fill with data using data adapter's Fill method 
     
         DataSet ds = new DataSet(); 
     
         da.Fill(ds, "Employees"); 
      
         // Hide the column and attach dataset's DefaultView to the datagrid control 
     
         ds.Tables["Employees"].Columns["LastName"].ColumnMapping = MappingType.Hidden; 
     
         dataGrid1.DataSource = ds.Tables["Employees"];
     
    2) Another way to hide a column is to set its width to zero. Check out the FAQ How do I set the width of a column in my DataGrid?.3) Another way to hide a column is to create a custom table style, and as you add columnstyles to your tablestyle, omit the column you want hidden. Check out the FAQ How do I add an unbound column in my bound DataGrid? to see how to create a custom table style.