【发布时间】:2016-08-19 05:54:41
【问题描述】:
我试图将 gridview 标签作为参数以根据该标签在 sql 中更新,但它显示错误,因为从对象类型 System.Web.UI.WebControls.Label 到已知托管提供程序本机类型不存在映射。请帮助我提前谢谢下面是我的代码
protected void btnSave_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStrCCUKYC"].ToString()))
{
foreach (GridViewRow row in ShowGrid.Rows)
{
var Clientid = row.Cells[5].FindControl("lblClientid");
// var Clientid = row.Cells[5].Text; Clientid is coming Null
//Label Clientid = ((Label)row.FindControl("lblClientid")); No mapping exists from object type System.Web.UI.WebControls.Label to a known managed provider native type.
CheckBox ckb = (CheckBox)row.FindControl("chkSelect");
//ckb.Checked = ((CheckBox)sender).Checked;
if (ckb.Checked==true)
{
var check = true;
SqlCommand cmd = new SqlCommand("sp_InsertRecieved_HOSignaturecard ", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Check", check);
cmd.Parameters.AddWithValue("@Clientid", Clientid);
con.Open();
var res = cmd.ExecuteNonQuery();
con.Close();
if (res > 0)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data Saved successfully..!')", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data NotSaved..!')", true);
}
}
else
{
var check = false;
SqlCommand cmd = new SqlCommand("sp_InsertRecieved_HOSignaturecard ", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Check", check);
cmd.Parameters.AddWithValue("@Clientid", Clientid);
con.Open();
var res = cmd.ExecuteNonQuery();
con.Close();
if (res > 0)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data Saved successfully..!')", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmsg", "alertify.alert('Data NotSaved..!')", true);
}
}
}
}
}
【问题讨论】: