Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What i have is a checkboxlist binded to student_Details datatable. when user's mouse hover over item (Student Name) in checkboxlist whole details of student in table should be displayed in tooltip.
Please help....
Posted
Updated 4-Apr-14 8:17am
v2
Comments
What have you tried?
Pawan Wagh 4-Apr-14 15:18pm    
i have tried something like this...
protected void Page_Load(object sender, EventArgs e)
{
string tooltip = string.Empty;
foreach (ListItem chk in CheckBoxList1.Items)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
try
{
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM Stud_Table WHERE Name='"+ chk.Text +"'";
con.Open();
SqlDataReader rd = cmd.ExecuteReader();
tooltip = rd[0].ToString() + Environment.NewLine + rd[1].ToString() + Environment.NewLine + rd[2].ToString();
}
catch (Exception ex)
{
string error_message = ex.Message;
Response.Write("<script LANGUAGE='JavaScript'>alert('" + error_message + "')</script>");
}
finally
{
con.Close();
}
}
}
chk.Attributes.Add("title", tooltip);
}
}
You have a tooltip variable defined? What have you tried to show that?
Pawan Wagh 4-Apr-14 15:52pm    
the details of item in checkboxlist like name,date of birth,address
Okay, but what you tried to achieve that.

OP has solved this himself.
C#
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
    string tooltip = string.Empty;
    foreach (ListItem chk in CheckBoxList1.Items)
    {
        using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                try
                {
                    cmd.Connection = con;
                    cmd.CommandText = "SELECT * FROM Stud_Table WHERE Name='" + chk.Text + "'";
                    con.Open();
                    SqlDataReader rd = cmd.ExecuteReader();
                    while(rd.Read())
                        tooltip = rd[0].ToString() + Environment.NewLine + rd[1].ToString() + Environment.NewLine + rd[2].ToString();
                    chk.Attributes.Add("title", tooltip);
                }
                catch (Exception ex)
                {
                    string error_message = ex.Message;
                    Response.Write("<script LANGUAGE='JavaScript'>alert('" + error_message + "')</script>");
                }
                finally
                {
                    con.Close();
                }
            }
        }    
    }
}
 
Share this answer
 

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