CheckBoxList Population and ToolTip

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arulmanoj
    New Member
    • Mar 2009
    • 34

    CheckBoxList Population and ToolTip

    Hi,

    I have a CheckBoxList in web form and I am populating the list items from the database in the page_load event. Now for each list item i have to set the tool tip using the value from the database.

    Code:
                    CheckBoxList1 .DataTextField = "Name";
                    CheckBoxList1.DataValueField = "Description";
                    CheckBoxList1.DataBind();
    Any idea please.

    Thanks
    Manoj.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Arulmanoj, as far as I know there is no "tooltip" for list items in a CheckBox list.
    You could very well add JavaScript to each item so that when you hover over the item it displays a description

    -Frinny

    Comment

    • Arulmanoj
      New Member
      • Mar 2009
      • 34

      #3
      Hi Frinny,

      Thanks for your reply.

      I don't know javascript. Can you please help me to write the javascript for the same. Sorry for asking this.

      Thanks

      Manoj.

      Comment

      • liawcv
        New Member
        • Jan 2009
        • 33

        #4
        1 workaround is to add the item one-by-one using a loop, rather than performing data binding. The "tooltip" of a ListItem can be set through its "Attributes " collection as follow:

        Code:
        ListItem li = new ListItem("Text", "Value");
        li.Attributes["title"] = "Tooltip";
        There is a problem -- Unlike "Text" and "Value" properties, values set through "Attributes " collection will not persist on postback. This mean, if this method is used, you will have to set the tooltip on every postback.

        An example here: The ASP.NET page contains a CheckBoxList named "cbl" and a Button that simply performs a postback. The CheckBoxList displays a list of file names from "C:\" folder. For each ListItem, file name is set as "Text" and full file name is set as "Value". The file creation time is set as "tooltip". Instead of performing data binding, I use a foreach loop to populate the ListItems. The codes are written within the Page_PreInit event handler (not sure if this is the appropriate place). I set its "EnableViewStat e" property to "False". As I populate the ListItems on every postback, there is no point to turn it on.

        Code:
        Using System.IO;
        ...
        protected void Page_PreInit(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"C:\");
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                ListItem li = new ListItem(file.Name, file.FullName);
                li.Attributes["title"] = file.CreationTime.ToString();
                cbl.Items.Add(li);
            }
        }
        Well. It may not be what you really want. Anyway, I hope at least this can give you an additional alternative idea to get your problem solved.

        Comment

        • liawcv
          New Member
          • Jan 2009
          • 33

          #5
          Another workaround is to place a single CheckBox (note: CheckBox has a Tooltip property) within a multiple-row DataBound control such as GridView, DataList, Repeater, ListView, etc. When the page is running, you will get a group of individual CheckBoxes.

          To check which CheckBoxes have been checked, you will have to visit each data row one-by-one. A bit "dirty", but still workable... : )

          Comment

          Working...