是否有可能在asp.net的下拉列表中显示工具提示

时间:2016-09-22 11:29:42

标签: javascript c# jquery asp.net

在我的网络应用程序中,我有dropdowncheckboxes控件,但我试图在selectbox项目上显示工具提示。是可以的。

我尝试了代码:

的.aspx:

<%@ Register Namespace="Saplin.Controls" Assembly="DropDownCheckBoxes" TagPrefix="asp"  %>

    <link rel="stylesheet" href="css/bootstrap-3.1.1.min.css" type="text/css" />
     <link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet" />
     <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
     <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
    script tag
      <script>
             $(function () {
                 $("#tooltip1").tooltip();
             });
          </script>

        <div class="tooltip1"> <asp:DropDownCheckBoxes ID="dropdown1" runat="server" UseSelectAllNode="true" UseButtons="true" OnSelectedIndexChanged="dropdown1_SelectedIndexChanged"
                                AutoPostBack="true"> <Style SelectBoxWidth="200" DropDownBoxBoxWidth="200" DropDownBoxBoxHeight="130" />
                        <Texts SelectBoxCaption="" />  
                                                 </asp:DropDownCheckBoxes> <asp:Label runat="server" ID="tooltip1"></asp:Label>

.CS:

protected void Page_Load(object sender, EventArgs e)
        {
            tooltip1.Text = dropdown1.Texts.SelectBoxCaption;
}
 protected void dropdown1_SelectedIndexChanged(object sender, EventArgs e)
        {

            List<String> checkedList = new List<string>();
            foreach (ListItem item in dropdown1.Items)
            {
                if (item.Selected)
                {
                    checkedList.Add(item.Value);
                }

            }            
            dropdown1.Texts.SelectBoxCaption = String.Join(",", checkedList.ToArray());
}

工具提示没有显示任何人都可以告诉我我错误的地方我不知道。是否有任何事件要显示工具提示

image description here

谢谢

1 个答案:

答案 0 :(得分:0)

以下方法正在为列表添加工具提示

public static void BindTooltip(ListControl lc)
    {
        for (int i = 0; i < lc.Items.Count; i++)
        {
            lc.Items[i].Attributes.Add("title", lc.Items[i].Text);
        }
    }
相关问题