Wednesday, 4 December 2013

How to show tooltip in DropDownList items on Mouseover event in asp.net using C#


In this article I will how to show tooltip in DropDownList items on Mouseover event in asp.net using C#

First we need bind data to DropDownList. See the below code for binding data to DropDownList.

Void BindDataToDropDownList()
{
  DataSet ds=new DataSet();
                ds = objUserRegistrationManager.GetSubDivision();
                ddlSubDivision.DataSource = ds;
                ddlSubDivision.DataValueField = "SDO_CD";
                ddlSubDivision.DataTextField = "SDO_CD";
                ddlSubDivision.DataBind();
}


After we can write the DataBound event for that DropDownList.

protected void ddlSubDivision _DataBound(object sender, EventArgs e)
{
DropDownList ddlDivision = sender as DropDownList;
if(ddlDivision!=null)
{
foreach (ListItem li in ddlDivision.Items)
{
li.Attributes["title"] = li.Text;
}
}

No comments:

Post a Comment