5

我正在使用 gridview 来显示数据,并且在 gridview 本身中我有一些操作按钮,例如编辑删除和预览图片视图。但我不想在我的预览按钮上显示文本“预览”,我想要(fontawesome 图标)而不是文本(预览)。我的代码在这里....

<asp:GridView ID="GVProduct" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CssClass="table table-bordered table-sm table-hover table-striped" EmptyDataText="No rows  for the selection criteria." EnableTheming="False" PageSize="5" OnRowCommand="grdForRows_RowCommand" OnPageIndexChanging="grdForRows_PageIndexChanging">
<Columns>
    <asp:BoundField DataField="ProId" HeaderText="Prod.Id">
        <HeaderStyle HorizontalAlign="Left" />
        <ItemStyle HorizontalAlign="Right" />
    </asp:BoundField>
    <asp:BoundField DataField="ProName" HeaderText="Product Name">
        <HeaderStyle HorizontalAlign="Left" />
        <ItemStyle HorizontalAlign="Left" />
    </asp:BoundField>
    <asp:BoundField DataField="ProCategory" HeaderText="Category">
        <HeaderStyle HorizontalAlign="Left" />
        <ItemStyle HorizontalAlign="Left" />
    </asp:BoundField>
    <asp:ButtonField Text="Preview" ButtonType="Button" HeaderText="Photo" CommandName="btnPreview">
        <ControlStyle CssClass="btn btn-success btn-sm" />
    </asp:ButtonField>
    <asp:ButtonField Text="Edit" ButtonType="Button" CommandName="btnEdit">
        <ControlStyle CssClass="btn btn-primary btn-sm" />
    </asp:ButtonField>
    <asp:ButtonField ButtonType="Button" CommandName="btnDelete" Text="Delete">
        <ControlStyle CssClass="btn btn-danger btn-sm" />
    </asp:ButtonField>
</Columns>

我要在按钮上添加的图标的代码是

<i class="fas fa-eye"></i>
4

3 回答 3

2

您可以从 Fontawesome 下载 SVG 文件,然后在 ImageButton 中添加带有“ImageUrl”标签的文件,如下所示:

<asp:TemplateField>
      <HeaderTemplate>
           <asp:Label ID="Label2" runat="server" Text="Edit" ToolTip="Edit"></asp:Label>
      </HeaderTemplate>
      <ItemTemplate>
           <asp:ImageButton runat="server" ImageUrl="~/context/Imagenes/Edit.svg" ID="Id" 
                CommandName="Command" />
      </ItemTemplate>
</asp:TemplateField>
于 2019-10-28T03:17:03.157 回答
2

我找到了将Font Awesome图标添加到GridView按钮的方法。使用ButtonType="Link"

<asp:GridView ID= ... >
   <Columns>
      ...
      <asp:ButtonField CommandName="myComand" Text="<i class='fa fa-info'></i>" 
      ButtonType="Link" ControlStyle-CssClass="btn btn-primary" />
      ...
   </Columns>
</asp:GridView>
于 2018-11-09T18:08:39.427 回答
-2

您可以使用图片
DeleteImageUrl="~/images/remove.png"

它是一个工作的我不知道为什么有些人给定负面的

<asp:CommandField ButtonType="Image" ShowDeleteButton="True" HeaderStyle-BackColor="LightBlue" DeleteImageUrl="~/images/remove.png" ItemStyle-Width="2%"></asp:CommandField>
于 2018-03-07T05:00:05.053 回答