Grid view delete and edit
i am using image button for edit and delete as item template and i give command name as edit, delete.. but my delete and edit operation not performed please help me
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
kalu singh raoRank #884 · 2.4K reputationPosted Aug 1, 2016, 9:41 PM EDT
Midhun TpRank #388 · 6.5K reputationPosted Aug 1, 2016, 9:33 PM EDT
Santosh Sasupalli178 reputationPosted Aug 1, 2016, 9:47 PM EDT
Santosh Sasupalli178 reputationPosted Aug 1, 2016, 9:53 PM EDT
BorderStyle="None" AutoGenerateEditButton="false" AutoGenerateDeleteButton="false" BorderWidth="2px" CellPadding="3" CellSpacing="2" AutoGenerateColumns="true" AlternatingRowStyle-Font-Italic="true"
Font-Names="Verdana" Font-Size="Small" AlternatingRowStyle-BackColor="Yellow" OnRowDeleting="edituser_RowDeleting" OnRowEditing="edituser_RowEditing">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="edit" runat="server" CommandName="Edit" CommandArgument='<%# Eval("uid") %>' text="edit" ImageUrl="content/images/file_edit.ico" ToolTip="Edit" Height="20px" Width="20px" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="delete" runat="server" CommandName="Delete" CommandArgument='<%# Eval("uid") %>' text="delete" ImageUrl="content/images/Delete_Icon.jpg" ToolTip="Delete" Height="20px" Width="20px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
{
formvalue = Convert.ToInt32(edituser.DataKeys[e.NewEditIndex].Values["uid"].ToString());
Response.Redirect("user_edit.aspx");
}
protected void edituser_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int i = Convert.ToInt32(edituser.DataKeys[e.RowIndex].Values["uid"].ToString());
usertable.deleteuser(i);
Response.Redirect("editusers.aspx");
}
protected void edituser_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Visible = false;
if (e.Row.RowType == DataControlRowType.DataRow)
{
string item = e.Row.Cells[3].Text;
ImageButton imgbtn = (ImageButton)e.Row.Cells[1].FindControl("delete");
if (imgbtn.CommandName == "Delete")
{
imgbtn.Attributes["onclick"] = "if(!confirm('Do you want to delete " + item + "?')){ return false;};";
}
}
}