ASP.NET: Tooltip in Datalist

In this article I explain how to add a tooltip. Here I provide an example to show a tooltip on the profile images.

In this article I explain how to add a tooltip. Here I provide an example to show a tooltip on the profile images. Like in the following image :

ASP.NETTooltip.jpg

First I bound a datalist from a database containing the details of users. I bound two fields, name and image, image is only for displaying in the datalist and name is to be shown in the tooltip.

Use the following procedure:

  1. Add the plugin jquery.tooltip. You can download it.
  2. Write the following code in the aspx page:
     

    <htmlxmlns="http://www.w3.org/1999/xhtml">

    <head>

    <title>Show Gridview Rows Details in tooltip with jQuery</title>

    <scriptsrc="http://code.jquery.com/jquery-1.8.2.js"type="text/javascript"></script>

    <%--<script src="jquery.tooltip.min.js" type="text/javascript"></script>--%>

        <scriptsrc="jquery-tooltip/jquery.tooltip.min.js"type="text/javascript"></script>

    <scripttype="text/javascript">

        function InitializeToolTip() {

            $(".datalistToolTip").tooltip({

                track: true,

                delay: 0,

                showURL: false,

                fade: 100,

                bodyHandler: function () {

                    return $($(this).next().html());

                },

                showURL: false

            });

        }

    </script>

    <scripttype="text/javascript">

        $(function () {

            InitializeToolTip();

        })

    </script>

    <styletype="text/css">

    #tooltip {

    position:absolute;

    z-index:1000;

    border:none;

    background-color:white;

     

    padding:0px;

    opacity:0.50;

    }

    #tooltiph3,#tooltipdiv { margin:0; }

    </style>

    </head>

    <body>

    <formid="form1"runat="server">

    <div>

        <br/>

        <br/>

        <br/>

        <br/>

        <asp:DataListID="DataList1"runat="server"RepeatDirection="Horizontal">

            <ItemTemplate>

     

                            <asp:LabelID="Label1"runat="server"Text='<%# Eval("Name")%>'Visible="false"></asp:Label>

               <ahref="#"><asp:ImageID="Image1"runat="server"ImageUrl='<%# Eval("image_path")%>'Width="50px"Height="50px"CssClass="datalistToolTip"/>

                <divid="tooltip"style="display:none;">

    <table>

    <tr>

    <td><%# Eval("Name")%></td>

    </tr>

     

    </table>

    </div></a>

            </ItemTemplate>

           

        </asp:DataList>

        <br/>

    &nbsp;</div>

       

    </form>

    </body>

    </html>
     

  3. Do not forget to bind a datalist from your database.

    When you are done, save the page and view the page in a browser; it will work perfectly.

    Here when you download the plugin, describe it in the head section as I did just to fetch the information of the tooltip on mouse hover.

    When you are done with the declarations in the head section in the aspx page and bind the datalist, add a table to the datalist item template field so that the tooltip can show the data you want. For example I added a div with the id "tooltip"; see:

    <divid="tooltip"style="display:none;">
    <
    table>
    <
    tr>
    <
    td><%# Eval("Name")%></td>
    </
    tr>
    </
    table>
    </div>

So, on mouse hover this div will show you the data that you want.