Add tooltip for dropdownlist items in asp.net with C# Example
Tooltip for dropdownlist items
In this Post explain how to add tooltip for dropdownlistitem in asp.net 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 asp.net:
We are going to demonstrate how add or display tool tip for dropdownlist items. For this we take a data table and get the data from data base by sqlconnection and bind tooltip for dropdownlist item. in this tutorial we also give one more example to showing tooltip on mouseoverevent in asp.net .
Asp.net Dropdownlist Related Post:
- Bind Dropdown by Dynamically
- Fill Dropdown By database.
- Adding or binding tooltip in each item of dropdownlist
- Check box in asp Dropdown List.
- DropDown List in asp.net Programming,
- Add ListItem in DropDownList asp.net c# Example
- Drop Down List control of asp.net
- Select option to the user from many items.
- Display tooltip from database for dropdownlist items in asp.net c# example
- Show tooltip dropdownlist items by mouseoverevent using C# example
- Example of Adding ToolTip for each Dropdown List Item in C#
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Bind Tooltips for Dropdownlist</title>
<style type="text/css">
p.MsoNormal
{margin-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:0in;
line-height:115%;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<br />
<p class="MsoNormal">
tooltip Example in dropdownlist items for asp.net</p>
Select
State here
<br />
<br />
<asp:DropDownList ID="ddlState" runat="server" ondatabound="ddlState_DataBound"/>
</div>
</form>
</body>
</html>
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";
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);
ddlState.DataTextField
= "StateName";
ddlState.DataValueField = "StateID";
ddlState.DataSource = datatable;
ddlState.DataBind();
}
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;
}
}
}
}
Asp.net
Programming web server control Related Post :
- Validation checkbox control using JavaScript
- Check box in ASP.NET GridView
- Ckeck
box list example-using-javascript.
- Asp.net checkbox list Example
- Asp.net Label control
- Textbox Asp.net control
- ImageButton control
- Asp.net Imagebutton control example
- Asp.net Button control.
- Literal
control in Asp.net
- Example of C# for Bind Data to asp.net Textbox inside gridview control
- Bind Data to asp.net textbox control in inside of gridview Using C# Example
Asp.net
Programming web server control Related Post :
- Validation checkbox control using JavaScript
- Check box in ASP.NET GridView
- Ckeck box list example-using-javascript.
- Asp.net checkbox list Example
- Asp.net Label control
- Textbox Asp.net control
- ImageButton control
- Asp.net Imagebutton control example
- Asp.net Button control.
- Literal control in Asp.net
- Example of C# for Bind Data to asp.net Textbox inside gridview control
- Bind Data to asp.net textbox control in inside of gridview Using C# Example
Comments
Post a Comment