it works for me, did you include the stylesheet to the page?<link rel="stylesheet" type="text/css" href="default.css">also, try to add a color to make sure it works:.newdatagrid
{
  color:red;
  width:200px
}

解决方案 »

  1.   

    没错的,思归,我一早就将css引用至该页面中了,html中很清楚<STYLE type="text/css">@import url( css/default.css ); 
    </STYLE>
      

  2.   

    try the following (note, you need to change the path of your css file):1. testcss.aspx:<%@ Import Namespace="System.IO" %>
    <STYLE type="text/css">
       @import url(default.css); 
    </STYLE>
    <form runat="server">
    <asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="false">
      <Columns>
                <asp:HyperLinkColumn
                     DataNavigateUrlField="Name"
     DataNavigateUrlFormatString="{0}"
     DataTextFormatString="{0}"
     DataTextField="Name"
                     HeaderText="Name"/>
                <asp:BoundColumn HeaderText="Size" 
                     DataField="Length"/>
             </Columns>
    </asp:DataGrid>
    </form><script language="C#" runat="Server">
    void Page_Load (Object o, EventArgs e)
    {
       string sPath = Server.MapPath(".");
       DirectoryInfo sr = new DirectoryInfo(sPath);
       FileInfo[] si = sr.GetFiles("*.*");
       BoundColumn bc = new BoundColumn();
       bc.ItemStyle.CssClass = "newdatagrid";
       bc.HeaderText="Creation Time";
       bc.DataField = "CreationTime";
       DataGrid1.Columns.Add(bc);
       DataGrid1.DataSource = si;
       DataGrid1.DataBind();
    }
    </script>2. default.css:.newdatagrid
    {
      color:red;
      width:200px
    }
      

  3.   

    控件有个属性:
    <asp:datagrid CssClass="mycss"/>