如何为封闭到数据源的checkboxlist中的每个项目设置工具提示? [英] How do I set tooltip for each item in checkboxlist binded to datasource ?

查看:103
本文介绍了如何为封闭到数据源的checkboxlist中的每个项目设置工具提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所拥有的是一个绑定到student_Details数据表的checkboxlist。当用户的鼠标悬停在复选框列表中的项目(学生姓名)上时,表格中学生的整个详细信息应显示在工具提示中。

请帮助....

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....

推荐答案

请参阅以下链接

为ListBox中的每个项目显示单独的工具提示 - .NET 2.0(C#代码) [ ^ ]

每个项目的工具提示列表框控件 [ ^ ]

http://social.msdn.microsoft.com/Forums/en-US/ c2e80333-7996-45ef-8acf-5f0a085a21e1 / display-a-tooltip-text-on-a-listbox-specific-item?forum = winformsdatacontrols [ ^ ]
See the following links
Showing a Separate Tooltip for Each Item in a ListBox - .NET 2.0 (C# Code)[^]
Listbox Control with Tooltip for Each Item[^]
http://social.msdn.microsoft.com/Forums/en-US/c2e80333-7996-45ef-8acf-5f0a085a21e1/displaying-a-tooltip-text-on-a-listbox-specific-item?forum=winformsdatacontrols[^]


OP已经解决了这个问题。

OP has solved this himself.
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();
                }
            }
        }    
    }
}


这篇关于如何为封闭到数据源的checkboxlist中的每个项目设置工具提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆