programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Monday, August 18, 2014

Add tooltip for dropdownlist items in with C# Example

Tooltip for dropdownlist items

In this Post explain how to add tooltip for dropdownlistitem in Programming. Some time the developers need this type of solution in web form when he wants to use dropdownlist with large text field. Then this is also called “Handle Long text problem in dropdownlist “.

How to display or add tooltip for dropdownlist items in

Now we give the code here.

Code for the Add tooltip in dropdownlist:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropDownlist_Item_tooltip.aspx.cs" Inherits="DropDownlist_Item_tooltip" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head id="Head1" runat="server">
<title>Bind Tooltips for Dropdownlist</title>
    <style type="text/css">

<form id="form1" runat="server">
<div align="center">
    <br />
    <p class="MsoNormal">
&nbsp;tooltip Example in dropdownlist items for</p>
    Select State here
    <br />
    <br />
<asp:DropDownList ID="ddlState" runat="server" ondatabound="ddlState_DataBound"/>

tooltip in dropdownlist in
tooltip in dropdownlist in

C# Code for the Add tooltip in dropdownlist:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class DropDownlist_Item_tooltip : System.Web.UI.Page
    string _connectionstring;
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            _connectionstring = @"Data Source=PARIJAT-PC\PARIJAT;Initial Catalog=Database1;Integrated Security=True;Pooling=False";

    protected void BindData()

        string _sql = "select StateID,StateName from States";
        SqlConnection _connection = new SqlConnection(_connectionstring);
        SqlCommand _command = new SqlCommand(_sql, _connection);
        SqlDataAdapter _adapter = new SqlDataAdapter(_command);
        DataTable datatable = new DataTable();
        ddlState.DataTextField = "StateName";
        ddlState.DataValueField = "StateID";
        ddlState.DataSource = datatable;
    protected void ddlState_DataBound(object sender, EventArgs e)
        DropDownList ddl = sender as DropDownList;
        if (ddl != null)
            foreach (ListItem li in ddl.Items)
                li.Attributes["title"] = li.Text;

No comments:

Post a Comment