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.

Wednesday, August 20, 2014

Example of Adding ToolTip for each Dropdown List Item in C#

Adding ToolTip for each Dropdown List Item in using C#:

In this post we describe how to add tool tip in dropdownlist item in The Tooltip is important when we use long length world in dropdown list name field.  In this tutorial we consider how to show tool tip of dropdownlist item on mouseover event and showing tooltip on mouse over event in dropdownlist and   many Example that are related to dropdown list, these are listed here:

Dropdownlist Related Post:

ToolTip for Dropdown List:

Now in this post we take a example and display data astooltip of each item of list.
Example of use tooltip in dropdownlist:
Consider a sql data base table and bind dropdownlist. Then create dropdownlist  DataBound function and bind name to tool tip title. Here we give the code also.

Tooltip Example of dropdownlist item code :

<%@ 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 />
<h2>Example of Adding ToolTip for each DropdownList Item in C#</h2>
    <p><strong>Select State here</strong></p>
    <br />
    <br />
<asp:DropDownList ID="ddlist" runat="server" ondatabound="ddlist_DataBound"

Tooltip on dropdownlist  each item C# code :

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();
        ddlist.DataTextField = "StateName";
        ddlist.DataValueField = "StateID";
        ddlist.DataSource = datatable;
    protected void ddlist_DataBound(object sender, EventArgs e)
        DropDownList ddl = sender as DropDownList;
        if (ddl != null)
            foreach (ListItem li in ddl.Items)
                li.Attributes["title"] = li.Text;
    protected void ddlist_SelectedIndexChanged(object sender, EventArgs e)


Other Related Post :

No comments:

Post a Comment