我刚刚在2010年使用Web部件模板填充了一个SPGridview(不使用VISUAL Web部件)。
以下是我的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放在哪里,以及如何应用它。
谢谢。
在您的web部件中,您可能希望使用在页面上包含CSS文件
CssRegistration.Register("/path/to/style.css");
若要在网格中应用样式,可以设置grid.CssClass
。
另请参阅,如何在我的Sharepoint WebPart中使用自定义CSS?。