使用VB.net的gridView列中的类图标(class icon in gridView column using VB.net)

编程入门 行业动态 更新时间:2024-10-28 00:25:58
使用VB.net的gridView列中的类图标(class icon in gridView column using VB.net)

我有一个GridView,我有一个名为class="icon-p"的CSS类。 我想在我的GridView列“修改”中使用ButtonType="Image" ,除了使用ButtonType="Image"和ImageUrl ..

这是我的GridView代码:

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CssClass="table" DataKeyNames="id_s" DataSourceID="SqlDataSource1"> <Columns> .. <asp:CommandField CancelText="cancel" DeleteText="delete" EditText="Update" HeaderText="Modify" ShowEditButton="True" ShowHeader="True" ButtonType="Image"/> </Columns> </asp:GridView>

I have one GridView and I have a CSS class called class="icon-p". I want to use this class in my GridView column "Modify", except using ButtonType="Image" and ImageUrl..`

Here is my GridView code:

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" CssClass="table" DataKeyNames="id_s" DataSourceID="SqlDataSource1"> <Columns> .. <asp:CommandField CancelText="cancel" DeleteText="delete" EditText="Update" HeaderText="Modify" ShowEditButton="True" ShowHeader="True" ButtonType="Image"/> </Columns> </asp:GridView>

最满意答案

在设计视图中右键单击GridView,然后转到编辑列。

找到命令字段,然后单击底部显示“转换为模板”的蓝色超链接。

退出并转到您的标记,您会发现各个控件都在那里,您可以通过它们来设置您的CssClass等。唯一使它成为更新按钮的是CommandName="Update"属性。

这篇文章详细介绍了我试图解释的转换步骤:

http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/

然后你会得到这样的东西:

<asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" Visible='<%# GetShowEditButton() %>' CommandName="Edit" Text="Edit"></asp:LinkButton> &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" Visible='<%# GetShowInsertButton() %>' CommandName="New" Text="New"></asp:LinkButton> &nbsp;<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" Visible='<%# GetShowDeleteButton() %>' ></asp:LinkButton> </ItemTemplate> </asp:TemplateField>

然后,您可以像这样设置CssClass:

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" Visible='<%# GetShowEditButton() %>' CommandName="Edit" Text="Edit" CssClass="icon-p"></asp:LinkButton>

Right click on your GridView in design view then go to edit columns.

Find the commandfield and click the blue hyperlink at the bottom that says "Convert to Template".

Exit back out and go to your markup and you will find that the individual controls are there and you can get at them to set your CssClass etc. The only thing that makes it an update button is the CommandName="Update" attribute.

This article here details the conversion steps that I was trying to explain:

http://peterkellner.net/2009/09/06/detailsview-gridview-aspnet-disable-new-edit-delete-buttons/

You will then be left with something like this:

<asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" Visible='<%# GetShowEditButton() %>' CommandName="Edit" Text="Edit"></asp:LinkButton> &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" Visible='<%# GetShowInsertButton() %>' CommandName="New" Text="New"></asp:LinkButton> &nbsp;<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" Visible='<%# GetShowDeleteButton() %>' ></asp:LinkButton> </ItemTemplate> </asp:TemplateField>

You can then set the CssClass like this for example:

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" Visible='<%# GetShowEditButton() %>' CommandName="Edit" Text="Edit" CssClass="icon-p"></asp:LinkButton>

更多推荐

本文发布于:2023-08-05 16:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1434038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图标   gridView   net   VB   icon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!