Reputation: 1
I have use the templete field delete button in gridview, so when I click on any delete button in the gridview to delete a row at that time it will give the deleting row index with that selected row's cells[0]
value. How can I do any one have a idea....?
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
int grdid = Int32.Parse(GridView3.Rows[index].Cells[0].Text);
IndiesProductDataContext ip = new IndiesProductDataContext();
ip.iLinks.DeleteAllOnSubmit(ip.iLinks.Where(c => c.ProductID == grdid));
ip.SubmitChanges();
}
I am using row command in gridview deleting row geting index but it does not work
Upvotes: 0
Views: 2847
Reputation: 1
i found The perfect solution of this problem...
protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow gvr = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
int RowIndex = gvr.RowIndex;
int ci = Int32.Parse(GridView3.Rows[RowIndex].Cells[1].Text);
ProductDataContext ip = new ProductDataContext();
ip.iLinks.DeleteAllOnSubmit(ip.iLinks.Where(c => c.PID == ci));
ip.SubmitChanges();
}
this code worked properly in my module...
Upvotes: 0
Reputation: 197
You can not do it in that way but you will have to use buttons click event to select the ID and then use that ID as perameter for second, different delete query.
Upvotes: 0
Reputation: 358
You can set CommandArgument property of button
In Aspx:
<asp:Button ID="btnDeleteContact" CommandName="DeleteContact"
CommandArgument="<%# Eval("ContactID") %>" runat="server" >Delete</asp:Button>
In _RowCommand event of GridView:
If e.CommandName = "DeleteContact" Then
Dim objContacts As New CContacts
objContacts.ContactID = e.CommandArgument
objContacts.DomainID = Session("DomainID")
Dim strError As String = objContacts.DelContact()
End If
hope it helps
Upvotes: 5