Bind or Adding tooltip for dropdownlist items in asp.net


DataBase Table:

first create databasetable as follows:

WebForm Design:

simply add one dropDownList to webform:

<asp:DropDownList ID=”DropDownList1″ runat=”server”
ondatabound=”DropDownList1_DataBound”>
</asp:DropDownList>

Connection string:

first prepare connection string in web.config file under configuration tag  as follows:

<connectionStrings>
<add name=”ConnectionString” connectionString=”Data Source=server2;Initial Catalog=Venkat123;Persist Security Info=True;User ID=sa;Password=123″/>
</connectionStrings>

Code Behind:

string connection = ConfigurationManager.ConnectionStrings[“ConnectionString”].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ FillDDL(); }
}
public void FillDDL()
{
SqlConnection con = new SqlConnection(connection);
SqlCommand cmd = new SqlCommand(“select UserId,UserName from Emp”,con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DropDownList1.DataValueField = “UserId”;
DropDownList1.DataTextField = “UserName”;
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
}
protected void DropDownList1_DataBound(object sender, EventArgs e)
{
DropDownList ddl = sender as DropDownList;
if (ddl != null)
{
foreach (ListItem li in ddl.Items)
{
li.Attributes[“title”] = li.Text;
}
}
}

OutputResult:

Advertisements

One thought on “Bind or Adding tooltip for dropdownlist items in asp.net

  1. This is a nice article. I have found another link that help to developers to create custom tooltip with custom dropdown list.www.mindstick.com/Articles/30062a03-ee92-40bb-bb7e-d9be0a666855/?Dynamic%20Tooltip%20on%20Custom%20Dr

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s