如何在ASP.NET中为DropDownList添加不同的列值作为Tooltip [英] How to add different column values as Tooltip for DropDownList in ASP.NET

查看:50
本文介绍了如何在ASP.NET中为DropDownList添加不同的列值作为Tooltip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.NET中为DropDownList添加不同的列值作为工具提示



我的数据表

-Seq_No int

-Name varchar(20)

-Address varchar(200)



i绑定来自dropdownlist的数据

textfield - 名称

Valuefield - Seq_No



我想用工具提示显示地址怎么办?

plz任何人都可以帮助我?

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??

推荐答案

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();
}


这篇关于如何在ASP.NET中为DropDownList添加不同的列值作为Tooltip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆