SPGridview CSS 不适用

发布于 2024-11-14 11:20:47 字数 2447 浏览 2 评论 0原文

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

以下是我的 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 放在哪里以及如何应用它。

谢谢。

I have just populated an SPGridview using webpart template in 2010 (NOT USING VISUAL WEBPART).

Following is my 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.

Please tell me where i can put my style.css and how can i apply the same.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-11-21 11:20:47

在 Web 部件中,您可能希望使用以下方法在页面上包含 CSS 文件:

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

要在网格中应用样式,您可以设置 grid.CssClass

另请参阅如何将自定义 CSS 与我的 Sharepoint WebPart 结合使用?< /a>.

In your web part, you'll probably want to include your CSS file on the page using:

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

To apply the styles in your grid, you can set grid.CssClass.

See also, How to use custom CSS with my Sharepoint WebPart?.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文