将按钮列“删除”替换为在 Gridview 中使用图像按钮
这是我的 Gridview 代码,
<asp:DataGrid id="dg" runat="server" ondeletecommand="Delete_Item" >
<columns>
<asp:buttoncolumn buttontype="LinkButton" commandname="Delete" text="Remove" />
</columns>
<HeaderStyle BackColor="#95C736" ForeColor="White" Font-Bold="True" />
</asp:DataGrid>
我想用图像替换我的按钮列,我必须对我的 GridView 做什么?
This is my Gridview code
<asp:DataGrid id="dg" runat="server" ondeletecommand="Delete_Item" >
<columns>
<asp:buttoncolumn buttontype="LinkButton" commandname="Delete" text="Remove" />
</columns>
<HeaderStyle BackColor="#95C736" ForeColor="White" Font-Bold="True" />
</asp:DataGrid>
I want to replace my buttoncolumn with an image, what must I do to my GridView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
我将为此使用模板列:
I would use a template column for this:
将 Button Column 替换为 TemplateColumn 允许您将标准 asp 控件放入其中。然后就可以正常处理Datagrid_ItemCommand事件了。
ItemCommand 处理程序类似于:
您需要做的唯一另一件事是将一些数据绑定到命令参数的图像按钮。我通常会这样做:
您还可以使用 asp:image 控件和 asp:Hyperlink 控件来获得相同的结果。
Replace the Button Column with a TemplateColumn with allows you to put standard asp controls inside. Then you can handle the Datagrid_ItemCommand event normally.
The ItemCommand handler would be something like:
The only other thing you would need to do is bind some data to the image button for a command argument. I usually do something like:
You could also use an asp:image control with an asp:Hyperlink control to get the same results.
我刚刚做的一件非常棒的事情就是将编码的 html 放入文本中。
Text="<img src='images/btn-find.png' class='ttip' alt='查看详细信息' />"
这让我知道只输入img src,还指定一个类和一个 alt 标签。您需要做的就是使用单刻度线并使用
gt
和lt
对您的<>
进行编码。One thing I just did that worked awesome is to put encoded html into the text.
Text="<img src='images/btn-find.png' class='ttip' alt='View Details' />"
This let me know only put in the img src, but also specify a class and an alt tag.All you need to do is use single tick marks and encode your
<>
withgt
andlt
.