I have two ListView the main one which will show you your CV Called CVLISTVIEW and inside this Listview there is Edit button called: EditCVBtn the code of this button is:
protected void EditCVBtn_Command(object sender, CommandEventArgs e)
{
ShowCVPanel.Visible = false;
editCVPanel.Visible = true;
if (Session["UsrNme"] != null)
{
using (SqlConnection RedMsgSQLCon = new SqlConnection(sc))
{
RedMsgSQLCon.Open();
SqlDataAdapter RedMsgDAADP = new SqlDataAdapter(@"SELECT * From CVs where UID=@UID And CVNum=@CVNum", sc);
var use = Session["UsrNme"];
Control myControl = FindControl("CVNumlbl");
RedMsgDAADP.SelectCommand.Parameters.AddWithValue("@UID", use);
RedMsgDAADP.SelectCommand.Parameters.AddWithValue("@CVNum", e.CommandArgument);
DataSet RedMsgCVs = new DataSet();
RedMsgDAADP.Fill(RedMsgCVs);
EditCVlistVw.DataSource = RedMsgCVs.Tables[0];
EditCVlistVw.DataBind();
}
}
else
{
}
}
Now as it mention into EditCVBtn code is to show the another ListView called EditCVlistVw someone will ask why you use two Listviews one to show CV and other to edit it, My answer is very simple as if I use one ListView with ItemTemplate and EditItemTemplate I will face many of problem with Cascading DropDownList as well as RequiredFieldValidator as well FileUpload. So now what is happen in the 2nd Listview (the one where you edit your CV) is when I click on UpdtCVBtn which is located into EditCVlistVw and behind code of this button is:
protected void UpdtCVBtn_Command(object sender, CommandEventArgs e)
{
SqlConnection EdCVCon = new SqlConnection(sc);
SqlCommand cmd = new SqlCommand();
if (Session["UsrNme"] != null)
{
string sqlstatment = @"Update CVs SET Birthday=@Birth, Gender=@Gend, PerInfo=@Pinfo, WorkEx=@WEXP, Educ=@Edu, SchAndCert=@SHOLcERT, Langu=@Lang, Hobbies=@Hobis, citiz=@Citzn, Linkden=@Linkden, PersWebsite=@PWeb, FN=@fn, LN=@ln, EMail=@mail, TeleNo=@tele, PersImg=@PIMG Where CVNum=@CVN)";
cmd.Connection = EdCVCon;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
cmd.Parameters.AddWithValue("@Birth", ((TextBox)EditCVlistVw.FindControl("UpdBirthdTxtBox")).Text);
cmd.Parameters.AddWithValue("@Gend", ((DropDownList)EditCVlistVw.FindControl("UpdGendrDDL")).SelectedValue);
cmd.Parameters.AddWithValue("@Pinfo", ((TextBox)EditCVlistVw.FindControl("UpdPerInfoTXT")).Text);
cmd.Parameters.AddWithValue("@WEXP", ((TextBox)EditCVlistVw.FindControl("UpdWorkExtxt")).Text);
cmd.Parameters.AddWithValue("@Edu", ((TextBox)EditCVlistVw.FindControl("UpdEducTxt")).Text);
cmd.Parameters.AddWithValue("@SHOLcERT", ((TextBox)EditCVlistVw.FindControl("UpdSchAndCertTXT")).Text);
cmd.Parameters.AddWithValue("@Lang", ((TextBox)EditCVlistVw.FindControl("UpdLanguTxt")).Text);
cmd.Parameters.AddWithValue("@Hobis", ((TextBox)EditCVlistVw.FindControl("UpdHobbiesTxt")).Text);
cmd.Parameters.AddWithValue("@Citzn", ((DropDownList)EditCVlistVw.FindControl("UpdJOBworlddrdolist")).SelectedValue);
cmd.Parameters.AddWithValue("@Linkden", ((TextBox)EditCVlistVw.FindControl("LinkdenTextBox")).Text);
cmd.Parameters.AddWithValue("@PWeb", ((TextBox)EditCVlistVw.FindControl("PWebtxtB")).Text);
cmd.Parameters.AddWithValue("@fn", ((TextBox)EditCVlistVw.FindControl("FNEditTxtBx")).Text);
cmd.Parameters.AddWithValue("@ln", ((TextBox)EditCVlistVw.FindControl("LNEditTxtBx")).Text);
cmd.Parameters.AddWithValue("@mail", ((TextBox)EditCVlistVw.FindControl("EmailEditTxt")).Text);
cmd.Parameters.AddWithValue("@tele", ((TextBox)EditCVlistVw.FindControl("TeleEditTxtB")).Text);
cmd.Parameters.AddWithValue("@PIMG", ((FileUpload)EditCVlistVw.FindControl("FileUpload1")).FileName);
EdCVCon.Open();
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
}
editCVPanel.Visible = false;
ShowCVPanel.Visible = true;
}
}
When I click on UpdtCVBtn I am facing this error message with all controls inside this ListView so how I can fix that??!!
Object reference not set to an instance of an object.
this error message show next to each line of controls
cmd.Parameters.AddWithValue("@Birth", ((TextBox)EditCVlistVw.FindControl("UpdBirthdTxtBox")).Text);