3
Answers

how to create edit,delete imagebutton and i clicked delete

how to create edit,delete imagebutton in gridview and i clicked delete button before delete conformation message show and i clicked edit button navigate to another form and that filled by select user details
Answers (3)
0
Midhun T P

Midhun T P

NA 19.7k 281.1k 8y
Hi,
You can try this -
<asp:GridView ID="grdnews" runat="server" GridLines="None"
Width="100%" OnRowDataBound="grd_RowDataBound" OnRowCommand="grd_Rowcommand"
CssClass="newstable">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:ImageButton runat="server" AutoPostBack="True" ID="btndelete" CommandArgument='<%#DataBinder.Eval(Container, "DataItem.yourID").ToString() %>'
OnClientClick="return confirm('Are you sure you want to delete?')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 .
 .
And in the rowcommand event, you can get yourid and perform database operations like below.
protected void grd_Rowcommand(object sender, GridViewCommandEventArgs e)
{
try
{
GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
int rowIndex = gvr.RowIndex;
ImageButton imgBtn = (ImageButton)grdnews.Rows[rowIndex].FindControl("btndelete");
string id = imgBtn.CommandArgument;
}
catch (Exception ex)
{
}
}
.
Same in the case of edit button.
Accepted
0
Rajeesh Menoth

Rajeesh Menoth

NA 24.7k 629.4k 8y
Hi,
 
Refer this articles :
 
http://www.advancesharp.com/blog/1101/insert-update-and-delete-in-asp-net-gridview-step-by-step
0
Ravi Patel

Ravi Patel

NA 7.8k 532.5k 8y
Hi ,
refer this
http://www.aspdotnet-suresh.com/2011/03/how-to-show-modalpopup-to-edit-gridview.html