Does anybody knows how to solve the following code? I need to load the image in de dropdown from a table and not from a folder.
here is my code
protected void BindTitles()
{
if (ddlCountry != null)
{
foreach (ListItem li in ddlCountry.Items)
{
li.Attributes["title"] = "Images/" + li.Text + ".png";
// Here i need to bind the image to the dropdown list...is it possible to do this in the BindDropDownList()? If so How?
}
}
}
/// <summary>
/// Bind Dropdownlist Data
/// </summary>
protected void BindDropDownList()
{
SqlConnection con = new SqlConnection("MyConn");
con.Open();
SqlCommand cmd = new SqlCommand("select * from LoadImage", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ddlCountry.DataTextField = "img_name";
ddlCountry.DataValueField = "img_image";
ddlCountry.DataSource = ds;
ddlCountry.DataBind();
con.Close();
}
you can't bind image in dorpdownlist, however one alternative could be to use jQuery for this. There's a nice plugin called ImageDropDown that does what you need.
I`m using j-query plugin for this...there are two problems with using this..
1. i need to load the images from a sql db into a dropdownlist(asp), normaly i can bind the image to the dropdownlist true refering the title as tooltip to the image path(li.Attributes["title"] = "Images/" + li.Text + ".png";
) bud because the value is comming directly from a database there is no path to bind, if we are talking abouth 10 images or so, then i would save the images in a temp folder, bud because we talking abouth 300 to 400 images this is not a option...so I hope
somebody knows a good work arround for this?
2. When i load the jquery image dropdownlist in a default.aspx(with no master page attached) everything works fine(If i load the images from a folder). Bud when i want to load the imagedropdown in a master page, it doesn`t load the the images(the text is
loaded)..does somebody has knowledge of this issue? and knows a workarround?
For first problem what you can do is use for loop and add item to the dropdownlist instead of using datasource and bind method. This way you will be able to loadd as many item to the dropdownlist option.
Second is a file reference issue. You can check the following post for an explanation-
Clubict
Member
223 Points
195 Posts
how to load image from sql table in jquery dropdownlist
Nov 12, 2012 06:44 PM|LINK
Hi,
Does anybody knows how to solve the following code? I need to load the image in de dropdown from a table and not from a folder.
here is my code
protected void BindTitles() { if (ddlCountry != null) { foreach (ListItem li in ddlCountry.Items) { li.Attributes["title"] = "Images/" + li.Text + ".png";// Here i need to bind the image to the dropdown list...is it possible to do this in the BindDropDownList()? If so How? } } } /// <summary> /// Bind Dropdownlist Data /// </summary> protected void BindDropDownList() { SqlConnection con = new SqlConnection("MyConn"); con.Open(); SqlCommand cmd = new SqlCommand("select * from LoadImage", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); ddlCountry.DataTextField = "img_name"; ddlCountry.DataValueField = "img_image"; ddlCountry.DataSource = ds; ddlCountry.DataBind(); con.Close(); }Best regards,
Mark
Yanping Wang...
Star
14919 Points
1537 Posts
Microsoft
Re: how to load image from sql table in jquery dropdownlist
Nov 15, 2012 12:53 AM|LINK
Hi Clubict,
you can't bind image in dorpdownlist, however one alternative could be to use jQuery for this. There's a nice plugin called ImageDropDown that does what you need.
http://www.marghoobsuleman.com/mywork/jcomponents/jquery-image-dropdown/index.html
hope this helps, thanks.
Feedback to us
Develop and promote your apps in Windows Store
asteranup
All-Star
30184 Points
4906 Posts
Re: how to load image from sql table in jquery dropdownlist
Nov 15, 2012 09:11 AM|LINK
Hi,
You can try msdropdownlist-
http://growingtech.blogspot.in/2012/02/using-msdropdown-dropdown-with-icon-in.html
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
Clubict
Member
223 Points
195 Posts
Re: how to load image from sql table in jquery dropdownlist
Nov 16, 2012 08:29 AM|LINK
Hi Yanping & Asteranup,
I`m using j-query plugin for this...there are two problems with using this..
1. i need to load the images from a sql db into a dropdownlist(asp), normaly i can bind the image to the dropdownlist true refering the title as tooltip to the image path(li.Attributes["title"] = "Images/" + li.Text + ".png"; ) bud because the value is comming directly from a database there is no path to bind, if we are talking abouth 10 images or so, then i would save the images in a temp folder, bud because we talking abouth 300 to 400 images this is not a option...so I hope somebody knows a good work arround for this?
2. When i load the jquery image dropdownlist in a default.aspx(with no master page attached) everything works fine(If i load the images from a folder). Bud when i want to load the imagedropdown in a master page, it doesn`t load the the images(the text is loaded)..does somebody has knowledge of this issue? and knows a workarround?
Best regards,
Mark
asteranup
All-Star
30184 Points
4906 Posts
Re: how to load image from sql table in jquery dropdownlist
Nov 16, 2012 08:37 AM|LINK
Hi,
For first problem what you can do is use for loop and add item to the dropdownlist instead of using datasource and bind method. This way you will be able to loadd as many item to the dropdownlist option.
Second is a file reference issue. You can check the following post for an explanation-
http://forums.asp.net/p/1742058/4695188.aspx/1?Re+CSS+couldn+t+be+retrieve+
http://delicious.com/anupdg/filereference
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog