Click here to Skip to main content
15,885,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir,
in my asp.net application, I stored all the employee information inside tbl_employee.But here I save the path of an image and his image in empimage folder.

How to retrieve this employee image and show it on an image control as per the employees, I have selected.

C#
protected void btnReset0_Click(object sender, EventArgs e)
  {
      string path = "";
      try
      {
          cmd.CommandText = "select EmpName,Department,StaffType,SubjectPrefer,Experience,Qualification,EmpId,image from tblEmployeeInformation where EmpName='" + DropDownList1.SelectedValue + "'";
          cmd.Connection = con;
          if (con.State == ConnectionState.Closed)
              con.Open();
          dr = cmd.ExecuteReader();
          if (dr.Read())
          {
              txtEmpName.Text = dr["EmpName"].ToString();
              ddlDepaartment.SelectedValue = dr["Department"].ToString();
              ddlSubPreference.SelectedValue = dr["SubjectPrefer"].ToString();
              ddlExperience.SelectedValue = dr["Experience"].ToString();
              ddlQualification.SelectedValue = dr["Qualification"].ToString();
              txtEmpId.Text = dr["EmpId"].ToString();
              path = dr["image"].ToString();
              if (path != null)
              {
                  Image1.ImageUrl = path;
              }
          }
          else
              Response.Write("<script LANGUAGE='JavaScript' >alert('-"+DropDownList1.SelectedValue+"-')</script>");
      }
      catch (Exception ex)
      {
          Response.Write("<script LANGUAGE='JavaScript' >alert('" + ex.Message + "')</script>");
      }
  }



Here the path from database retrieve to the path variable, but does not show the image in image control.
Posted
Updated 2-Aug-14 20:48pm
v3

1 solution

Set returned image path from database to ImageUrl from codebehind like this
C#
Image1.ImageUrl = "Image_Path";
 
Share this answer
 
Comments
bigyan sahoo 3-Aug-14 3:03am    
image path has stored in the imageurl but it does not show the image
Dilan Shaminda 3-Aug-14 4:46am    
can you post the code here?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900