Click here to Skip to main content
15,910,121 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

How to get image in Image Box from saved path on Dropdownlist selected index changed event in c# asp.net?
I am using this code for display image in image box on Dropdownlist selected index changed:-
 protected void DDLCity_SelectedIndexChanged(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(connectionString);

        SqlCommand cmd = new SqlCommand("procGetSponsorDetails", con);
        con.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@CityId", SqlDbType.Int).Value = DDLCity.SelectedItem.Value;
        SqlDataReader sdr = cmd.ExecuteReader();
        
        if (sdr.Read())
        {

            ImgLogoSponsor.ImageUrl = Server.MapPath("~/Templates/") + sdr[0].ToString();
            LblAllotedCards.Text = "You have " + sdr[10].ToString() + " free/sponsored cards";
        }
        sdr.Close();
        con.Close();
}


when I am debugging so, Image path show in ImgLogoSponsor.ImageUrl (Image Url) but Image it's not showing in image box on dropdownlist selected index changed event, in c# asp.net.

Please help me.

Thanks in Advance.

Ankit Agarwal
Web Developer
Posted
Updated 4-Feb-14 20:13pm
v3
Comments
JoCodes 5-Feb-14 2:03am    
Are you sure the Image url is correct? Are you getting the full path?
[no name] 5-Feb-14 2:13am    
Ya of course.
sri senthil kumar 5-Feb-14 4:34am    
Can you please post the image path your getting?

1 solution

remove server.mapPath

simply provide
string st1="~/temp/temp1";

Imag1.ImageUrl=st1;
or
Imag1.ImageUrl="~/temp/temp1";

it will work
 
Share this answer
 

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