简体   繁体   English

SPGridview CSS 不适用

[英]SPGridview CSS not applying

I have just populated an SPGridview using webpart template in 2010 (NOT USING VISUAL WEBPART).我刚刚在 2010 年使用 webpart 模板填充了一个 SPGridview(不使用 VISUAL WEBPART)。

Following is my CreateChildControls()以下是我的 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();
}

This populates data but with the default style.这会填充数据,但使用默认样式。 I want my custom css to be applied.我希望应用我的自定义 css。

Please tell me where i can put my style.css and how can i apply the same.请告诉我我可以把我的风格放在哪里。css 以及我如何应用它。

Thanks.谢谢。

In your web part, you'll probably want to include your CSS file on the page using:在您的 web 部分中,您可能希望使用以下命令在页面上包含您的 CSS 文件:

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

To apply the styles in your grid, you can set grid.CssClass .要在网格中应用 styles,可以设置grid.CssClass

See also, How to use custom CSS with my Sharepoint WebPart?另请参阅, 如何将自定义 CSS 与我的 Sharepoint WebPart 一起使用? . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM