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

Thursday, August 21, 2014

Display tooltip from database for dropdownlist items in asp.net c# example

Example of Display tooltip from database for dropdownlist items in asp.net c#




In this post we describe a Example for display tooltip in dropdownlist each item in asp.net.  And the importance of Tooltip is in web development we can use long length world in dropdown list in name field.  In this asp.net Programming tutorial we consider a post how to show tool tip of dropdownlist item on mouseover event and  many Examples that’s refers to dropdown list, these are listed here each have relation to dropdownlist example:
Asp.net Dropdownlist Related Post:

Display ToolTip for Dropdown List:
Now in this post we take an example and display data as tooltip of each item of list.

Example of use tooltip in dropdownlist in c#:


Take a sql database table and bind dropdownlist. Then create dropdownlist  DataBound Method and using this bind name to tooltip. Here we give the code for solving this in asp.net using C#.

Show Tooltip Example of dropdownlist item code :

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="PageHead1" runat="server">
    <style type="text/css">

     .P
       {       
       font-size:14.0pt;
       font-family:"Calibri","sans-serif";
       }
    </style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
    <br />
   
<h2> Display tooltip from database for dropdownlist items Example</h2>
    <p><strong>Select State for this dropdownlist </strong></p>
    <br />
    <br />
<asp:DropDownList ID="myddlist" runat="server" ondatabound="myddlist_DataBound"  onselectedindexchanged="myddlist_SelectedIndexChanged"/>
</div>
</form>
</body>
</html>


Use 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 DropDownlistItemtooltip : 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";
            BindData();
        }
    }

    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();
        _adapter.Fill(datatable);
        myddlist.DataTextField = "StateName";
        myddlist.DataValueField = "StateID";
        myddlist.DataSource = datatable;
        myddlist.DataBind();
    }
    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;
            }
        }
    }
    protected void myddlist_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}


Other Asp.net Related Post :

No comments:

Post a Comment