Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have a gridview on my webform, In that GRIDVIEW I have 5000 Records. and also I gave paging to it.... its working fine.

i have assign a tool tip for every row. on the first page of gridview it is showing Tool tip for every cell.

But when i click page 2 under paging....its unable to show tooltip.


Please can u suggest me , how to do this.

Thanks.
Posted
Comments
Sunasara Imdadhusen 30-May-12 5:14am    
Please provide snippet of code!
Ranjith Reddy CSE 30-May-12 5:31am    
Page_Load
==========

foreach (GridViewRow item in GridView1.Rows)
{
item.Cells[2].BackColor = Color.FromName("#6698FF");


string StudentCode = item.Cells[2].Text;
StudentCode = StudentCode.Substring(0, 2);

string sc = getstudentcode(StudentCode);
item.Cells[2].ToolTip = sc;



public string getStudentcode(string Studentcode)
{
string result = "Test";
SqlConnection con = new SqlConnection("Data Source=Ranjith-pc;Initial Catalog=StudentsDB;User Id=sa;Password=123;");

SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select StudentName from StudentsCode where Code='" + StudentCode + "'";

using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
result = reader["StudentName"].ToString();
}

}
return result;
}

// Paging

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
John Orendt 30-May-12 5:45am    
please show entire Page_Load method
Ranjith Reddy CSE 30-May-12 6:02am    
This is my code
================

protected void Page_Load(object sender, EventArgs e)
{
foreach (GridViewRow item in GridView1.Rows)
{
item.Cells[2].BackColor = Color.FromName("#6698FF");


string StudentCode = item.Cells[2].Text;
StudentCode = StudentCode.Substring(0, 2);

string sc = getstudentcode(StudentCode);
item.Cells[2].ToolTip = sc;
}


public string getStudentcode(string Studentcode)
{
string result = "Test";
SqlConnection con = new SqlConnection("Data Source=Ranjith-pc;Initial Catalog=StudentsDB;User Id=sa;Password=123;");

SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select StudentName from StudentsCode where Code='" + StudentCode + "'";

using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
result = reader["StudentName"].ToString();
}

}
return result;
}

// Paging

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
Ranjith Reddy CSE 30-May-12 6:07am    
This is my perfect code
=========================
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Drawing;
using System.Collections.Specialized;
using System.Text.RegularExpressions;

public partial class Users_StudentDetails : System.Web.UI.Page
{
private static readonly string _connString = String.Empty;
SqlConnection con = new SqlConnection(_connString);

protected void Page_Load(object sender, EventArgs e)
{

foreach (GridViewRow item in GridView1.Rows)
{
item.Cells[2].BackColor = Color.FromName("#6698FF");


string StudentCode = item.Cells[2].Text;
StudentCode = StudentCode.Substring(0, 2);

string sc = getstudentcode(StudentCode);
item.Cells[2].ToolTip = sc;
}
}


public string getStudentcode(string Studentcode)
{
string result = "Test";
SqlConnection con = new SqlConnection("Data Source=Ranjith-pc;Initial Catalog=StudentsDB;User Id=sa;Password=123;");

SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select StudentName from StudentsCode where Code='" + StudentCode + "'";

using (con)
{
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
result = reader["StudentName"].ToString();
}

}
return result;
}

// Paging

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}

static Users_StudentDetails()
{
_connString = WebConfigurationManager.ConnectionStrings["StudentsDBConnectionString"].ConnectionString;
}


}

1 solution

Try to implement tool tip on RowDataBound Event. Hope It will Work fine for all Pages in paging.
 
Share this answer
 
Comments
Ranjith Reddy CSE 30-May-12 6:22am    
Thank you So much my dear Friend.....its working in RowDataBound Event...thanx a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900