我想要使用ASP.NET GridView CommandField。 一切正常工作,就在我将CommandField属性声明从页面移动到皮肤文件时,整个commandField属性都被忽略。这是我的皮肤文件:
<asp:GridView
AllowPaging="true"
AllowSorting="false"
AutoGenerateEditButton="false"
AutoGenerateDeleteButton="false"
AutoGenerateSelectButton="false"
AutoGenerateColumns="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>
在web.config中我只应用StyleSheetTheme。我错过了什么吗?
由于
答案 0 :(得分:1)
我明白了:
文字内容
<asp:CommandField
ButtonType="Image"
ShowDeleteButton="true"
ItemStyle-Width="25"
DeleteImageUrl="~/App_Themes/SimplaAdmin/Images/Icons/cross.png"
/>
不允许在皮肤文件中使用。
答案 1 :(得分:1)
这可以通过使用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>
详情请参阅以下
答案 2 :(得分:0)
如果要使用 Fontawesome 图标,可以按以下方式进行更改:
<asp:CommandField ButtonType="Link" ShowEditButton="true"
EditText="<i class='fas fa-edit'></i>" />
用于删除用途:
DeleteText="<i class='fas fa-trash-alt'></i>"
用于Canel:
CancelText="<i class='fas fa-window-close'></i>"
用于更新:
UpdateText="<i class='fas fa-sync'></i>"
答案 3 :(得分:-1)
如果将CommandField标记移到GridView标记之外会发生什么?
即:
<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"
/>