Reputation: 151
I am not very experienced and perhaps I am asking a stupid question. I'm trying to delete a row inside this gridview. To do this, I call a method deleteDettagliDocument(id_row)
to perform a DELETE
from my DB. This method takes an integer as parameter but the control is a Label and I can't cast it properly. Here's my code.
protected void grdContact_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
bool result;
DboDocument objdbo = new DboDocument();
InvoiceDetails ID = new InvoiceDetails();
List<InvoiceDetails> app = (List<InvoiceDetails>)Session["lst_details"];
int id_row = (Label)grdContact.Rows[e.RowIndex].FindControl("lblId_Row"); // Error!
app.RemoveAt(e.RowIndex);
Session["lst_details"] = app;
FillGrid();
CalculateTotal();
result = objdbo.deleteDocumentDetails(id_row);
}
Upvotes: 0
Views: 1029
Reputation: 1950
You are trying to assign Label
to int
,
Label lbl = grdContact.Rows[e.RowIndex].FindControl("lblId_Row") as Label;
if(lbl != null)
{
int id_row = int.Parse(lbl.Text);
}
Upvotes: 3