In this article I will explain how to change the style of tooltips in asp.net using JQuery.
Description:
DataType | |
UserId | Int(set identity property=true) |
UserName | varchar(50) |
LastName | varchar(50) |
Location | varchar(50) |
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Change Gridview Tooltips</title> <link href="jquery.tooltip.css" rel="stylesheet" type="text/css" /> <script src="js/jquery.js" type="text/javascript"></script> <script src="js/jquery.tooltip.js" type="text/javascript"></script> <script src="js/jquery.dimensions.js" type="text/javascript"></script> <script type="text/javascript" language="javascript"> $(function() { $('#userdiv *').tooltip(); }) </script> <style type="text/css"> .GridviewDiv {font-size: 100%; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helevetica, sans-serif; color: #303933;} Table.Gridview{border:solid 1px #df5015;} .Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em 0.5em 0.5em 0.5em;text-align:center} .Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em 0.5em;} .Gridview tr{color: Black; background-color: White; text-align:left} :link,:visited { color: #DF4F13; text-decoration:none } </style> </head> <body> <form id="form1" runat="server"> <div id="userdiv"> <table> <tr> <td> <asp:Label ID="lblUrl" runat="server" ToolTip="URL" Text="URL" Font-Bold="true"/> </td> <td> <a title="Aspdotnet-Suresh offers C#.net,Asp.net,SQL Server articles" href="http://www.aspdotnet-suresh.com">www.aspdotnet-suresh.com</a> </td> </tr> <tr> <td> <asp:Label ID="lblUser" runat="server" ToolTip="UserName" Font-Bold="true" Text="Enter UserName:"/> </td> <td> <asp:TextBox ID="txtUser" runat="server" ToolTip="Enter UserName" /> </td> </tr> <tr> <td> <asp:Label ID="lbllName" runat="server" ToolTip="LastName" Font-Bold="true" Text="Enter LastName:"/> </td> <td> <asp:TextBox ID="txtLastName" runat="server" ToolTip="Enter LastName"/> </td> </tr> <tr> <td> <asp:Label ID="lblLocation" runat="server" ToolTip="Location" Font-Bold="true" Text="Enter Location:"/> </td> <td> <asp:TextBox ID="txtLocation" runat="server" ToolTip="Enter Location"/> </td> </tr> </table> <div id="test" class="GridviewDiv"> <asp:GridView ID="gvdetails" runat="server" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="true" Width="540px" PageSize="10" CssClass="Gridview" OnRowDataBound ="gvdetails_RowDataBound" OnPageIndexChanging="gvdetails_PageIndexChanging" > <HeaderStyle BackColor="#df5015" /> <Columns> <asp:BoundField DataField="UserId" HeaderText="UserId" /> <asp:BoundField DataField="UserName" HeaderText="UserName" /> <asp:BoundField DataField="LastName" HeaderText="LastName" /> <asp:BoundField DataField="Location" HeaderText="Location" /> </Columns> </asp:GridView> </div> </div> </form> </body> </html> |
using System; using System.Data; using System.Data.SqlClient; using System.Web.UI.WebControls; |
C# Code
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindDropdownlist(); } } protected void BindDropdownlist() { SqlConnection con = new SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true"); con.Open(); SqlCommand cmd = new SqlCommand("select * from UserInformation", con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); gvdetails.DataSource = ds; gvdetails.DataBind(); con.Close(); } protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvdetails.PageIndex = e.NewPageIndex; BindDropdownlist(); } protected void gvdetails_RowDataBound(object sender, GridViewRowEventArgs e) { //This condition is used to check RowType is Header if (e.Row.RowType == DataControlRowType.Header) { for (int i = 0; i < gvdetails.Columns.Count; i++) { e.Row.Cells[i].ToolTip = gvdetails.Columns[i].HeaderText; } } if (e.Row.RowType == DataControlRowType.DataRow) { foreach (TableCell gvcell in e.Row.Cells) { gvcell.ToolTip = gvcell.Text; } } } | |
Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI.WebControls Partial Class ToolTipinVB Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then BindDropdownlist() End If End Sub Protected Sub BindDropdownlist() Dim con As New SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true") con.Open() Dim cmd As New SqlCommand("select * from UserInformation", con) Dim da As New SqlDataAdapter(cmd) Dim ds As New DataSet() da.Fill(ds) gvdetails.DataSource = ds gvdetails.DataBind() con.Close() End Sub Protected Sub gvdetails_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) gvdetails.PageIndex = e.NewPageIndex BindDropdownlist() End Sub Protected Sub gvdetails_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) 'This condition is used to check RowType is Header If e.Row.RowType = DataControlRowType.Header Then For i As Integer = 0 To gvdetails.Columns.Count - 1 e.Row.Cells(i).ToolTip = gvdetails.Columns(i).HeaderText Next End If If e.Row.RowType = DataControlRowType.DataRow Then For Each gvcell As TableCell In e.Row.Cells gvcell.ToolTip = gvcell.Text Next End If End Sub End Class |
In our application header section I used only single property $('#userdiv *').tooltip(); to change the tooltip style. We can change the stlye of tooltip in different by using different properties to know more about this JQuery plugin check these sites bassistance.de and JQuery tooltip demo page jquery.bassistance.de
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|



Subscribe by RSS
Subscribe by Email
6 comments :
Nice Post brother.........keep on going...
Its good .
U doing well MR.Suresh
nice post keet on going.
please provide latest technology.
loving it broa! yo tight!
Grt job sir...