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.

Thursday, August 21, 2014

Add or bind tooltip for dropdownlist items in by C#

Add or bind tooltip for dropdownlist items in :

In Previous Post we describe clearly “how to show tooltip ofdropdownlist item in” and Example Demo for using tooltip for each itemof dropdownlist item using C#. Now we will explain how to add tooltips for each item of dropdown list in Programming

(Handle Long text problem in dropdownlist using

 When we are working to web development in many times we will use dropdownlists in our web application, if it have more length of data then we will not be able to see entire data within the dropdown list then we use this technique. So here we take a example to bind tooltip forsql database using C# code.

Example of C# Dropdownlist Related Post:

Adding ToolTip of Dropdownlist control:

Now in this post we take an example that consider how to display data as tooltip in C# of each item of list.

Code of dropdownlist data bound method:
protected void myddlist_DataBound(object sender, EventArgs e)
        DropDownList ddl = sender as DropDownList;
        if (ddl != null)
            foreach (ListItem li in ddl.Items)
                li.Attributes["title"] = li.Text;
 bind tooltip for dropdownlist items in by C#

Tooltip in dropdownlist control each item C# code :

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
    <title>tooltips for each item of dropdown list in Programming for database</title>
    <style type="text/css">
    <form id="form1" runat="server">
    <div align="center">
        <br />
            Example of Adding or binding ToolTip with each DropdownList Item in C#</h2>
            <strong>Select State here and see full data on mouseover event</strong></p>
        <br />
        <br />
        <asp:DropDownList ID="ddlist" runat="server" OnDataBound="ddlist_DataBound" />

DropDownlist_Itemtooltip page C# code Example:

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_Itemtooltip : 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