Example of Adding ToolTip for each Dropdown List Item in C#
Adding ToolTip for each Dropdown List Item in asp.net using C#:
In this post we describe how to add tool tip in dropdownlist item in asp.net. The Tooltip is important when we use long length world in dropdown
list name field. In this asp.net 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:
- Bind Dropdown by Dynamically
- Check box in asp Dropdown List.
- Fill Dropdown By database.
- Adding or binding tooltip in each item of dropdownlist
- DropDown List in asp.net Programming,
- Drop Down List control of asp.net
- Add ListItem in DropDownList asp.net c# Example
- 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#.
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 asp.net 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" "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-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:0in;
line-height:90%;
font-size:14.0pt;
font-family:"Calibri","sans-serif";
}
</style>
</head>
<body>
<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"
onselectedindexchanged="ddlist_SelectedIndexChanged"/>
</div>
</form>
</body>
</html>
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";
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);
ddlist.DataTextField = "StateName";
ddlist.DataValueField = "StateID";
ddlist.DataSource = datatable;
ddlist.DataBind();
}
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
Asp.net Related Post :
- What is the postback in asp.net
- Post back And call back
- Use of view state.
- events in asp.net
- control execution life cycle.
- asp.net-user-control-basics.
- server control.
- image size before Uploading.
- Introduction of SQL
- 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