在asp.net gridview中,我使用的是图片点击功能,但不起作用?
<asp:GridView ID="GVPending" DataKeyNames="Userid" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="#">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name"></asp:BoundField>
<asp:BoundField DataField="Branch" HeaderText="Branch"></asp:BoundField>
<asp:BoundField DataField="Address" HeaderText="Address"></asp:BoundField>
<asp:BoundField DataField="EmailAddress" HeaderText="Email"></asp:BoundField>
<asp:BoundField DataField="Phonenumber" HeaderText="Phone Number"></asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnEdit" runat="server" CommandName="Approve" ImageUrl="~/approve.jpg" OnClick="btnEdit_Click" ToolTip="Approve" style="
width: 30px;
"/>
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Decline" ImageUrl="~/delete.jpg" OnClick="btnDelete_Click" ToolTip="Decline" style="
width: 30px;
" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
代码:
protected void btnEdit_Click(object sender, ImageClickEventArgs e)
{
ImageButton lbtn = (ImageButton)sender;
GridViewRow row = (GridViewRow)lbtn.NamingContainer;
if (row != null)
{
string userid = Convert.ToString(GVPending.DataKeys[row.RowIndex].Value);
}
}
在这种情况下,onclick不会触发。请仔细阅读我提交的设计和代码。如果有人帮助,它将对我很有帮助