设置DataGrid 的 AutoGenerateColumns="False",然后使用 <asp:BoundColumn>
<asp:datagrid id="DataGrid1" runat="server" BorderWidth="1px" BorderColor="Black" Font-Size="12pt"
AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="#aaaadd" PagerStyle-HorizontalAlign="Right"
CellPadding="3" AllowPaging="True" AllowCustomPaging="True" AutoGenerateColumns="False" OnPageIndexChanged="MyDataGrid_Page"
PageSize="15" AllowSorting="True" OnSortCommand="DataGrid1_SortCommand">
<AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
<ItemStyle Font-Size="Smaller" BorderWidth="22px"></ItemStyle>
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="ID" SortExpression="ID" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="订单ID" HeaderText="订单ID"></asp:BoundColumn>
<asp:BoundColumn DataField="产品ID" HeaderText="产品ID"></asp:BoundColumn>
<asp:BoundColumn DataField="单价" HeaderText="单价"></asp:BoundColumn>
<asp:BoundColumn DataField="数量" HeaderText="数量"></asp:BoundColumn>
<asp:BoundColumn DataField="折扣" HeaderText="折扣"></asp:BoundColumn>
</Columns>
<PagerStyle Font-Names="VerDana" Font-Bold="True" HorizontalAlign="Right" ForeColor="Coral"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>

解决方案 »

  1.   

    如何控制DataGrid中各个单元格的样式,如2003-09-01 00:00:00变成
    2003/09/01.???
    给你一个函数
    //把字符串年月日后面的时间去除,也可用于带空格的其它字符串
    public static string changeString(string ss)
    {
    string lkk="";
    for(int i=ss.Length;i>0;i--)
    {
    char lk=ss[i-1];
    if(lk==' ')
    {
    lkk=ss.Substring(0,i);
    break;
    }
    }
    return lkk;
    }
      

  2.   

    更多信息参考MSDN:ms-help://MS.MSDNQTR.2003FEB.2052/cpgenref/html/cpconDataGridWebServerControl.htm
      

  3.   

    更多信息参考MSDN:ms-help://MS.MSDNQTR.2003FEB.2052/cpgenref/html/cpconDataGridWebServerControl.htm
      

  4.   

    请问,这是写在aspx页面中,不是写在aspx.cs中的吗?
      

  5.   

    直接卸载aspx文件中的,你最好参考我叫你看的MSDN文档,因为DataGrid这个控件的功能非常强大,不是一两句话就说清楚的。
      

  6.   

    看看这个
    <asp:datagrid id="MyDataGrid" runat="server" AutoGenerateColumns="False" HorizontalAlign="Center"  ItemStyle-ForeColor="#cccccc"
    AlternatingItemStyle-BackColor="#f5f5f5" HeaderStyle-BackColor="#F6F6F6" Font-Size="11pt" Font-Name="Verdana" CellSpacing="0" CellPadding="3"
    GridLines="Both" BorderWidth="1" BorderColor="#D1D1D1" OnPageIndexChanged="MyDataGrid_Page" PagerStyle-HorizontalAlign="center" PagerStyle-Mode="NumericPages"
    PageSize="20" AllowPaging="True">
    <AlternatingItemStyle BackColor="#F6F6F6"></AlternatingItemStyle>
    <HeaderStyle BackColor="#F6F6F6" Font-Bold="True" HorizontalAlign="Center" Height="30"></HeaderStyle>
    <PagerStyle HorizontalAlign="center" Mode="NumericPages"></PagerStyle>
    <Columns>
    <asp:BoundColumn HeaderText="ID" DataField="Id" HeaderStyle-Width="60px" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="b" DataField="b" HeaderStyle-Width="100px" ItemStyle-Height="25"
    ItemStyle-ForeColor="#FF6600" ItemStyle-HorizontalAlign="Center" ></asp:BoundColumn>
    <asp:BoundColumn HeaderText="c" DataField="c" HeaderStyle-Width="100px" ItemStyle-Height="25"
    ItemStyle-ForeColor="#8FB127" ItemStyle-HorizontalAlign="Center" ></asp:BoundColumn>
    </Columns>
    </asp:datagrid
      

  7.   

    http://aspnet.4guysfromrolla.com/articles/040502-1.aspxAn Extensive Examination of the DataGrid Web Control[01] The basics of the DataGrid  
    [02] specifying display properties of the DataGrid  
    [03] associate custom events with the DataGrid.  
    [04] provide custom sorting on the results of a DataGrid.  
    [05] use templates to further customize the DataGrid's appearance.  
    [06] use the DataGrid's built-in edit ing capabilities,  
    [07] customizing the editing interface using the EditItemTemplate .  
    [08] add client-side code to a ButtonColumn 's client-side onclick event.  
    [09] enhance the DataGrid's editing interface by having the editing interface's TextBox receive focus when the page is loaded.  
    [10] (automatically) add filter ing buttons so that one can filter the data in a DataGrid.  
    [11] create a DataGrid Web control with a column of related radio buttons .  
    [12] create a sort able DataGrid that can be sorted in ascending and descending order.  
    [13] sum up a DataGrid column and have the sum displayed in the footer .  
    [14] build a master/detail DataGrid.  
    [15] add paging support to the DataGrid!