2011-06-08 47 views
0

我剛在2010年使用webpart模板填充了SPGridview(不使用VISUAL WEBPART)。SPGridview CSS不適用

以下是我的CreateChildControls()

protected override void CreateChildControls() 
{ 

    private SPGridView oGrid; 
    private DataView oView; 

    this.ChromeType = PartChromeType.BorderOnly; 
    oView = new DataView(Returnds()); 

    oGrid = new SPGridView(); 
    oGrid.DataSource = oView; 
    oGrid.AutoGenerateColumns = false; 

    oGrid = new SPGridView(); 
    oGrid.DataSource = oView; 
    oGrid.AutoGenerateColumns = false; 
    oGrid.AllowSorting = true; 
    oGrid.Sorting += new GridViewSortEventHandler(oGrid_Sorting); 

    SPMenuField colMenu = new SPMenuField(); 
    colMenu.ItemStyle.Width = new Unit(200, UnitType.Pixel); 
    colMenu.HeaderText = "Title"; 
    colMenu.TextFields = "Title"; 
    colMenu.MenuTemplateId = "PresenterListMenu"; 
    colMenu.NavigateUrlFields = "ID"; 
    colMenu.NavigateUrlFormat = "do.aspx?p={0}"; 
    colMenu.TokenNameAndValueFields = "EDIT=ID"; 
    colMenu.SortExpression = "Title"; 

    MenuTemplate presenterListMenu = new MenuTemplate(); 
    presenterListMenu.ID = "PresenterListMenu"; 
    MenuItemTemplate biogMenu = new MenuItemTemplate("View Goal", "/_layouts/images/Icon_view_Item.png"); 
    biogMenu.ClientOnClickNavigateUrl = "do.aspx?Id=%EDIT%"; 

    presenterListMenu.Controls.Add(biogMenu); 

    MenuSeparatorTemplate sepMenu = new MenuSeparatorTemplate(); 
    presenterListMenu.Controls.Add(sepMenu); 

    MenuItemTemplate broadcastMenu = new MenuItemTemplate("Edit Goal", "/_layouts/images/ICWM.gif"); 
    presenterListMenu.Controls.Add(broadcastMenu); 

    this.Controls.Add(presenterListMenu); 
    oGrid.Columns.Add(colMenu); 

    BoundField colProgramme = new BoundField(); 
    colProgramme.DataField = "Name"; 
    colProgramme.HeaderText = "Name"; 
    colProgramme.SortExpression = "Name"; 
    oGrid.Columns.Add(colProgramme); 

    Controls.Add(oGrid); 

    oGrid.PageSize = 2; 
    oGrid.EmptyDataText = "No Records Found !!"; 
    oGrid.AllowPaging = true 
    oGrid.PagerTemplate = null; 
    oGrid.AllowSorting = true; 

    oGrid.PageIndexChanging += new GridViewPageEventHandler(oGrid_PageIndexChanging); 
    oGrid.RowDataBound += new GridViewRowEventHandler(oGrid_RowDataBound); 
    oGrid.Sorting += new GridViewSortEventHandler(oGrid_Sorting); 

    oGrid.DataBind(); 
    base.CreateChildControls(); 
} 

該填充數據,但在默認樣式。我希望我的自定義CSS被應用。

請告訴我,我可以把我的style.css,我怎麼能應用相同的。

謝謝。

+0

你解決了這個問題? – TinTin 2011-07-13 11:38:45

回答

0

在你的網絡的一部分,你可能會想包括在頁面上使用的CSS文件:

CssRegistration.Register("/path/to/style.css"); 

要應用的樣式在你的網格,您可以設置grid.CssClass。另外,How to use custom CSS with my Sharepoint WebPart?