标签转换findcontrol
Label convert findcontrol
我不是很有经验,也许我在问一个愚蠢的问题。我正在尝试删除此 gridview 中的一行。为此,我调用方法 deleteDettagliDocument(id_row)
从我的数据库中执行 DELETE
。此方法采用一个整数作为参数,但控件是一个标签,我无法正确转换它。这是我的代码。
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);
}
您正在尝试将 Label
分配给 int
、
Label lbl = grdContact.Rows[e.RowIndex].FindControl("lblId_Row") as Label;
if(lbl != null)
{
int id_row = int.Parse(lbl.Text);
}
我不是很有经验,也许我在问一个愚蠢的问题。我正在尝试删除此 gridview 中的一行。为此,我调用方法 deleteDettagliDocument(id_row)
从我的数据库中执行 DELETE
。此方法采用一个整数作为参数,但控件是一个标签,我无法正确转换它。这是我的代码。
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);
}
您正在尝试将 Label
分配给 int
、
Label lbl = grdContact.Rows[e.RowIndex].FindControl("lblId_Row") as Label;
if(lbl != null)
{
int id_row = int.Parse(lbl.Text);
}