SPGridview CSS 不适用
我刚刚在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Web 部件中,您可能希望使用以下方法在页面上包含 CSS 文件:
要在网格中应用样式,您可以设置
grid.CssClass
。另请参阅如何将自定义 CSS 与我的 Sharepoint WebPart 结合使用?< /a>.
In your web part, you'll probably want to include your CSS file on the page using:
To apply the styles in your grid, you can set
grid.CssClass
.See also, How to use custom CSS with my Sharepoint WebPart?.