我有一个小问题。我正在 Web 部件中动态创建一个 SPGridView,并将其添加到其中包含一些数据的 Web 部件。这很好用。我现在决定让它看起来有点时髦!!
但是我似乎无法让我的 cssclass 属性发挥作用。
我在css文件中有一个类
.SPGridviewsCSS th
{
background-color:#e60004;
color: Blue!important;
background-image:none;
}
.SPGridviewsCSS td
{
border-bottom-style: solid ;
border-bottom-width: 1px ;
border-bottom-color: #e60004 ;
}
和 在我的 oninit 事件中
CssRegistration.Register("/Styles/Style.css");
然后
myspgridview.cssclass = "SPGridviewsCSS"
我只想让 GridView 看起来好看!!!
最佳答案
我正在为 SPGridView 样式使用一些服务器代码。这不是一个非常优雅的解决方案,但它工作得很好。如果您没有太多时间找到更好的解决方案,您可以在您的用户控件或 aspx 页面中使用此代码,其中放置了 SPGridView 控件:
protected override void CreateChildControls()
{
// ...
spGridView.RowStyle.CssClass = "spgridview-td";
spGridView.AlternatingRowStyle.CssClass = "spgridview-td-alternating";
this.Controls.Add(spGridView);
// ...
}
当然,您可以使用 aspx 标记来代替生成控件。例如:
<asp:SPGridView ID="spGridView" runat="server">
<RowStyle CssClass="spgridview-td" />
<AlternatingRowStyle CssClass="spgridview-td-alternating" />
</asp:SPGridView>
接下来是将样式附加到标题:
protected override void Render(HtmlTextWriter writer)
{
// ...
spGridView.DataBind();
if (spGridView.HeaderRow != null)
foreach (TableCell cell in spGridView.HeaderRow.Cells)
cell.CssClass = "spgridview-th";
// ...
}
因此,您的 CSS 将是:
.spgridview-th
{
background-color:#e60004;
color: Blue!important;
background-image:none;
}
.spgridview-td
{
border-bottom-style: solid ;
border-bottom-width: 1px ;
border-bottom-color: #e60004 ;
}
.spgridview-td-alternating
{
}
希望这对您有所帮助!
关于c# - SpGridView 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3726017/