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

this my data table
-Seq_No int
-Name varchar(20)
-Address varchar(200)

i am bind a data from dropdownlist
textfield - Name
Valuefield - Seq_No

I want to display a Address using tooltip how to do it??
plz any one can help me??
Posted

1 solution

C#
protected void btnLoad_Click(object sender, EventArgs e)
{
    string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["sqlConnection"].ToString();
    
    SqlConnection conn = new SqlConnection(strCon);
    conn.Open();
    SqlDataAdapter da = null;
    DataSet dsCountry = new DataSet();
    try
    {
        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();
    
        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());
        }
        DropDownList1.Items.Insert(0, new ListItem("--Select--", "--Select--"));
        DropDownList1.SelectedItem.Selected = false;
        DropDownList1.Items.FindByText("--Select--").Selected = true;
    }
    catch (Exception ex)
    {
        lblMsg.Text = "Error!! <br>+" + ex.Message.ToString();
    }
    finally
    {
        dsCountry.Dispose();
        da.Dispose();
        conn.Close();
        conn.Dispose();
}
 
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