when i click on register button i am getting all values but when i upload pic it is showing null value help me out sir
if (TextBox2.Text == "")
{
Response.Write("");
return;
}
else if (TextBox3.Text == "")
{
Response.Write("");
return;
}
else if (TextBox4.Text == "")
{
Response.Write("");
return;
}
string Gender = "";
if (RadioButton1.Checked == true)
{
Gender = RadioButton1.Text;
}
else
{
Gender = RadioButton2.Text;
}
string country = Convert.ToString(DropDownList1.SelectedItem);
string state = Convert.ToString(DropDownList2.SelectedItem);
string cit = Convert.ToString(DropDownList3.SelectedItem);
if (Button1.Text == "Register")
{
if (FileUpload1.HasFile && FileUpload2.HasFile)
{
string profileImageName = FileUpload1.PostedFile.FileName;
string profileImage = FileUpload2.PostedFile.FileName;
string filePath = Server.MapPath(@"~/Images/" + profileImageName);
string newfilepath = Server.MapPath(@"~/Images/" + profileImage);
FileUpload1.SaveAs(filePath);
FileUpload2.SaveAs(newfilepath);
string commandText = "insert into masterwithimg values ('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + Convert.ToInt64(TextBox5.Text) + "','" + Gender + "','" + country + "','" + state + "','" + cit + "','~/Images/" + profileImageName + "','~/Images/" + profileImage + "')";
var com = new SqlCommand(commandText, Con);
Con.Open();
int result = com.ExecuteNonQuery();
if (result > 0)
{
BindEmployeeData();
}
else
{
Response.Write("nothing");
}
Con.Close();
}
Sachin SinghPosted Mar 1, 2023, 7:16 AM
first test this,
after selecting country,state and city at last select the file and Register.
I am sure, you are first selecting the file then selecting country, state and your dropdown is making a postback request which is making your fileupload null.
so , please select the profile image at last and then click on register it will work.
Then i will share the proper solution.
Jaya PrakashPosted Mar 1, 2023, 6:55 AM
Users\source\repos\MasterWithImg\MasterWithImg\Images' is denied. getting error like thisJignesh KumarPosted Mar 1, 2023, 6:16 AM
Hello Jaya prakash,
Please refer this article its doing exatcly same you are looking for,
https://www.c-sharpcorner.com/UploadFile/77a82c/binding-image-with-gridview-and-update-image-in-gridview/