Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to fetch image on page load from table in which the path of image is stored and the actual image is in the folder of solution. I have used image control. should i use another control ? in ASP.net
Posted
Comments
MAYANK GEETE 14-Mar-14 9:35am    
just fetch your data into datatable then
string path = dt.rows[0]["IMGpath"].tostring();
ImageButton1.ImageUrl = "~//" + path;
jayraj86 14-Mar-14 11:57am    
My code is as below. I just want to display image on page load. i am using image control. what changes i should make in this code ?

protected void Page_Load(object sender, EventArgs e)
{

if (Convert.ToInt16(Session["CompanyID"].ToString()) > 0)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Companies where CompanyID=" + Session["CompanyID"], con);
SqlDataAdapter da = new SqlDataAdapter(cmd);


DataSet ds = new DataSet();

da.Fill(ds, "Companies");

if (ds.Tables[0].Rows.Count > 0)
{
email.Text = ds.Tables[0].Rows[0]["EmailID"].ToString();
firstname.Text = ds.Tables[0].Rows[0]["FirstName"].ToString();
lastname.Text = ds.Tables[0].Rows[0]["LastName"].ToString();
designation.Text = ds.Tables[0].Rows[0]["Designation"].ToString();
mobile.Text = ds.Tables[0].Rows[0]["ContactNo"].ToString();


Label9.Text = ds.Tables[0].Rows[0]["CompanyName"].ToString();
Label10.Text = ds.Tables[0].Rows[0]["City"].ToString();
Label16.Text = ds.Tables[0].Rows[0]["Address"].ToString();
Label11.Text = ds.Tables[0].Rows[0]["Website"].ToString();
Label12.Text = ds.Tables[0].Rows[0]["CompanyCategory"].ToString();
Label13.Text = ds.Tables[0].Rows[0]["NoOfEmployees"].ToString();
Label15.Text = ds.Tables[0].Rows[0]["Aboutcompany"].ToString();

}
}
}
}
}
ZurdoDev 14-Mar-14 11:43am    
I don't understand your question. You're asking if you should use something other than the image control to show an image? No. Use the image control.
jayraj86 14-Mar-14 11:49am    
My code is as below. I just want to display image on page load. i am using image control. what changes i should make in this code ?

protected void Page_Load(object sender, EventArgs e)
{

if (Convert.ToInt16(Session["CompanyID"].ToString()) > 0)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Companies where CompanyID=" + Session["CompanyID"], con);
SqlDataAdapter da = new SqlDataAdapter(cmd);


DataSet ds = new DataSet();

da.Fill(ds, "Companies");

if (ds.Tables[0].Rows.Count > 0)
{
email.Text = ds.Tables[0].Rows[0]["EmailID"].ToString();
firstname.Text = ds.Tables[0].Rows[0]["FirstName"].ToString();
lastname.Text = ds.Tables[0].Rows[0]["LastName"].ToString();
designation.Text = ds.Tables[0].Rows[0]["Designation"].ToString();
mobile.Text = ds.Tables[0].Rows[0]["ContactNo"].ToString();


Label9.Text = ds.Tables[0].Rows[0]["CompanyName"].ToString();
Label10.Text = ds.Tables[0].Rows[0]["City"].ToString();
Label16.Text = ds.Tables[0].Rows[0]["Address"].ToString();
Label11.Text = ds.Tables[0].Rows[0]["Website"].ToString();
Label12.Text = ds.Tables[0].Rows[0]["CompanyCategory"].ToString();
Label13.Text = ds.Tables[0].Rows[0]["NoOfEmployees"].ToString();
Label15.Text = ds.Tables[0].Rows[0]["Aboutcompany"].ToString();

}
}
}
}
}
ZurdoDev 14-Mar-14 11:50am    
I don't see an image control. Add an image control and set it's image path to the url of where it is.

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