[英]Change AutoGeneratedDelete LinkButton of Gridview to an Image Button
i have a gridview with AutoGenerateDeleteButton Property set true. 我有一个将AutoGenerateDeleteButton属性设置为true的gridview。 Of course this property auto generates a linkbutton at the leftmost of the gridview, my question is, how can i change it to an Image Button??
当然,此属性会自动在gridview的最左侧生成一个linkbutton,我的问题是,如何将其更改为Image Button? i wanted my gridview to look more presentable by making the control buttons an image.
我希望通过使控制按钮成为图像,使Gridview看起来更像样。
Thanks! 谢谢! :)
:)
You can do by using template in grid... 您可以通过在网格中使用模板来完成...
for more info 了解更多信息
http://p2p.wrox.com/asp-net-2-0-professional/46216-image-button-template-field-gridview-control.html http://p2p.wrox.com/asp-net-2-0-professional/46216-image-button-template-field-gridview-control.html
You can create a TemplateField
and use autogeneratecolumns="false"
. 您可以创建一个
TemplateField
并使用autogeneratecolumns="false"
。
Here's an example of a GridView: 这是GridView的示例:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="Link" runat="server" Text="click" OnClick="link_Click"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="field1" HeaderText="My Column 1" />
<asp:BoundField DataField="field2" HeaderText="My Column 2" />
</Columns>
</asp:GridView>
Where field1
and field2
are headers from your DataTable
其中
field1
和field2
是DataTable
表的标题
And to access the row within the event handler: 并访问事件处理程序中的行:
protected void link_Click(object sender, EventArgs e)
{
int rowindex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;
//do something with rowindex etc
}
Add new Template Column and in add image button and set CommandName='Delete' it'll raise the delete event automatically. 添加新的模板列,并在添加图像按钮中设置CommandName ='Delete',它将自动引发delete事件。
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgDelete" ImageUrl="~/imgs/Delete.png"
CommandName="Delete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.