GridView 中图片按钮后面的调用函数 [英] call function behind the image button in GridView
本文介绍了GridView 中图片按钮后面的调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 gridview 中有两个按钮,但是在使用我在其中写入函数名称的CommandName"后它们没有返回任何事件,但它没有做任何事情.
i am having two buttons in the gridview but they dont return anything event after using the "CommandName" in which i write the function name but it does not do anything.
截图如下:
两个按钮是编辑和删除.
the two buttons are edit and delete.
这是片段:
<asp:ButtonField ButtonType="Image" ImageUrl="~/wp-content/themes/realia/assets/img/edit pencil change modify alter blue edit icon2.png" CausesValidation="true" Text="Edit" CommandName="Edit_data">
<ControlStyle Height="30px" Width="30px" />
</asp:ButtonField>
<asp:ButtonField ButtonType="Image" ImageUrl="~/wp-content/themes/realia/assets/img/500px-Delete_Icon2.png" Text="Delete">
<ControlStyle Height="30px" Width="30px" />
</asp:ButtonField>
c#:
protected void Edit_data(object sender, EventArgs e)
{
Response.Write("hello");
}
推荐答案
<asp:GridView ID="gvProduct" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
OnRowCommand="gvProduct_RowCommand" Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnEdit" runat="server" CommandName="EditCommand" ImageUrl="~/Images/Grid/edit.png"
/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProjectNo" />
<asp:BoundField DataField="OrderLetterNo" />
<asp:BoundField DataField="Date" />
<asp:BoundField DataField="Saloon" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete" runat="server" CommandName="DeleteCommand" ImageUrl="~/Images/Grid/delete.png" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是背后的代码:
protected void gvProduct_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow Row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
int rowID = Convert.ToInt32(gvProduct.DataKeys[Row.RowIndex].Value);
if (e.CommandName == "EditCommand")
{
EditFunction(rowID);
}
else
if (e.CommandName == "DeleteCommand")
{
DeleteFunction(rowID);
}
}
这篇关于GridView 中图片按钮后面的调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文