Hi aspvijay04,
Check this example. Now please take its reference and correct your code.
Database
I have used Employees table from Northwind database.
Install Microsoft Northwind and Pubs Sample databases in SQL Server Management Studio
HTML
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/jquery.simpletip/1.3.1/jquery.simpletip-1.3.1.min.js"></script>
<style type="text/css">
.tooltip
{
position: absolute;
top: 0;
left: 0;
z-index: 3;
display: none;
background-color: #FB66AA;
color: White;
padding: 5px;
font-size: 10pt;
font-family: Arial;
}
td
{
cursor: pointer;
}
</style>
<script type="text/javascript">
$(function () {
var row;
$('[id*=GridView1] tr:has(td)').mouseover(function () {
var employeeId = $(this).find("td:first").html();
row = $(this);
$.ajax({
type: "POST",
url: '<%=ResolveUrl("Default.aspx/GetEmployeeAddress") %>',
data: '{employeeId: "' + employeeId + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
row.find("td").each(function () {
$(this).simpletip({
content: response.d
});
});
},
failure: function (response) {
alert(response.d);
}
});
});
});
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="EmployeeId" HeaderText="EmployeeId" ItemStyle-Width="30" />
<asp:BoundField DataField="FirstLast" HeaderText="Name" ItemStyle-Width="180" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
</div>
Namespaces
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.PopulateEmployees();
}
}
[System.Web.Services.WebMethod]
public static string GetEmployeeAddress(string employeeId)
{
string address = string.Empty;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Address + ',' + City + ',' + Country 'Address' FROM Employees WHERE EmployeeId = @EmployeeId", conn))
{
cmd.Parameters.AddWithValue("@EmployeeId", employeeId);
conn.Open();
address = cmd.ExecuteScalar().ToString();
conn.Close();
return address;
}
}
}
private void PopulateEmployees()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT EmployeeId, FirstName + ' ' + LastName FirstLast, Country FROM Employees", conn))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
}
Screenshot
