Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
How to add different column values as Tooltip for DropDownList in ASP.NET

Am try this code text change event.ot's not working.

plase anyone can help how to fix this.

XML
string strCountrySQL = "select id, name, Address from dbo.Customer";
                da = new SqlDataAdapter(strCountrySQL, conn);
                da.Fill(dsCountry);
                DropDownList1.DataSource = dsCountry;
                DropDownList1.DataTextField = "name";
                DropDownList1.DataValueField = "id";
                DropDownList1.DataBind();



<pre lang="cs">int ItemCount = DropDownList1.Items.Count;
               for (int i = 0; i &lt; ItemCount; i++)
               {
                   DropDownList1.Items[i].Attributes.Add(&quot;Title&quot;, dsCountry.Tables[0].Rows[i][&quot;Address&quot;].ToString());
               }</pre>
Posted
Updated 12-Mar-13 21:16pm
v2

What you've done is RIGHT!!!...

int ItemCount = DropDownList1.Items.Count;
for (int i = 0; i < ItemCount; i++)
{
DropDownList1.Items[i].Attributes.Add("title", dsCountry.Tables[0].Rows[i]["Address"].ToString());
}


Should work in FireFox, Netscape, and Safari. But not in IE

More info:
http://forums.asp.net/t/903935.aspx/1[^]


Mark it if you find this useful.
 
Share this answer
 
v2
Try this
C#
string strCountrySQL = "select id, name, Address from dbo.Customer";
                da = new SqlDataAdapter(strCountrySQL, conn);
                da.Fill(dsCountry);


List<listitem> lst = new List<listitem>();
C#
for (int i = 0; i < dt.Rows.Count; i++)
            {
                lst.Add(new ListItem(dsCountry.Tables[0].Rows[i]["Name"].ToString() + dt.Rows[i]["Address"].ToString(), dsCountry.Tables[0].Rows[i]["ID"].ToString()));
            }



DropDownList1.Items.AddRange(lst.ToArray());


This may help you
 
Share this answer
 
v2

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