简体   繁体   English

将Gridview的AutoGeneratedDelete LinkBut​​ton更改为图像按钮

[英]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! 谢谢! :) :)

Try this 尝试这个

<Columns>
   <asp:CommandField ButtonType="Image" DeleteImageUrl="~/Images/DeleteImage.png"
      ShowDeleteButton="true"/>
</Columns>

And set AutoGenerateDeleteButton="false" 并设置AutoGenerateDeleteButton="false"

Or Refer this too 或也参考

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 其中field1field2DataTable表的标题

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM