ASP.NET CommandField & skin
I'm tying to skin ASP.NET GridView CommandField. Everything si working fine, just when I move CommandField property declarations from page to skin file, the whole commandField properties are ignored. here is my skin file:
<asp:GridView
AllowPaging="true"
AllowSorting="false"
AutoGenerateEditButton="false"
AutoGenerateDeleteButton="false"
AutoGenerateSelectButton="false"
Auto开发者_StackOverflow中文版GenerateColumns="false"
GridLines="None"
PageSize="20"
ShowFooter="false"
ShowHeader="true"
runat="server">
<Columns>
<asp:CommandField
ButtonType="Image"
ControlStyle-Width="25"
EditImageUrl="Images/Icons/pencil.png"
DeleteImageUrl="Images/Icons/cross.png"
/>
</Columns>
</asp:GridView>
In web.config I apply only StyleSheetTheme. Do I miss something?
Thanks
This can be achieved by using StyleSheetTheme and NOT Theme.
Following is the control style defined in a .skin file
<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" />
The web.config file defines the StyleSheetTheme as site level
<pages styleSheetTheme="Green" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
The .aspx page containing the GridView control
<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>
For detail please refer to the following
- http://weblogs.asp.net/vimodi/ThemesFaqs
- http://weblogs.asp.net/vimodi/WhatIs-StyleSheetTheme
Hope this helps!
I get:
Content of literal
<asp:CommandField
ButtonType="Image"
ShowDeleteButton="true"
ItemStyle-Width="25"
DeleteImageUrl="~/App_Themes/SimplaAdmin/Images/Icons/cross.png"
/>
is not allowed within a skin file.
If you want to use a Fontawesome icon, you can change it like that:
<asp:CommandField ButtonType="Link" ShowEditButton="true"
EditText="<i class='fas fa-edit'></i>" />
for Delete use:
DeleteText="<i class='fas fa-trash-alt'></i>"
for Canel use:
CancelText="<i class='fas fa-window-close'></i>"
for Update use:
UpdateText="<i class='fas fa-sync'></i>"
What happens if you move the CommandField tag outside of the GridView tag?
i.e.:
<asp:GridView
AllowPaging="true"
AllowSorting="false"
AutoGenerateEditButton="false"
AutoGenerateDeleteButton="false"
AutoGenerateSelectButton="false"
AutoGenerateColumns="false"
GridLines="None"
PageSize="20"
ShowFooter="false"
ShowHeader="true"
runat="server">
</asp:GridView>
<asp:CommandField
ButtonType="Image"
ControlStyle-Width="25"
EditImageUrl="Images/Icons/pencil.png"
DeleteImageUrl="Images/Icons/cross.png"
/>
精彩评论