这可以通过使用 StyleSheetTheme 和 NOT Theme 来实现。
以下是 .skin 文件中定义的控件样式
<asp:GridView runat="server" Font-Names="verdana,arial,sans serif" AllowSorting="True" AllowPaging="True" AutoGenerateColumns="False" Width="95%">
<Columns>
<asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/Buttons/16x16/Cancel.gif"
EditImageUrl="~/Images/Buttons/16x16/Edit.gif" ShowEditButton="True" InsertImageUrl="~/Images/Buttons/16x16/New.gif" UpdateImageUrl="~/Images/Buttons/16x16/Update.gif" />
<asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/Buttons/16x16/Delete.gif"
ShowDeleteButton="True" />
</Columns>
<RowStyle Font-Size="Smaller" ForeColor="Black" />
<PagerStyle Font-Size="Smaller" ForeColor="Black" />
<SelectedRowStyle BackColor="Yellow" />
<HeaderStyle BackColor="#2D5C3D" Font-Size="Smaller" ForeColor="White" HorizontalAlign="left" />
<FooterStyle BackColor="#2D5C3D" />
<EditRowStyle BackColor="#2D5C3D" />
<AlternatingRowStyle BackColor="#ECE9D8" />
web.config 文件将 StyleSheetTheme 定义为站点级别
<pages styleSheetTheme="Green" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
包含 GridView 控件的 .aspx 页
<asp:GridView ID="gvUser" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" onpageindexchanged="gvUser_PageIndexChanged"
onpageindexchanging="gvUser_PageIndexChanging"
onrowcancelingedit="gvUser_RowCancelingEdit" onrowdeleting="gvUser_RowDeleting"
onrowediting="gvUser_RowEditing" onrowupdating="gvUser_RowUpdating"
onselectedindexchanging="gvUser_SelectedIndexChanging" onsorted="gvUser_Sorted"
onsorting="gvUser_Sorting">
<Columns>
<asp:BoundField DataField="Id" HeaderText="User Id" >
<HeaderStyle HorizontalAlign="Right" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" />
</asp:BoundField>
</Columns>
</asp:GridView>
详情请参考以下
- http://weblogs.asp.net/vimodi/ThemesFaqs
- http://weblogs.asp.net/vimodi/WhatIs-StyleSheetTheme
希望这可以帮助!