在 asp.net listview itemtemplate 中使用 qTip

发布于 2024-11-07 05:37:21 字数 1456 浏览 1 评论 0原文

我正在尝试在 ASP.NET ListView 中使用 qTip 。该页面使用 MasterPage。每个项目中有一个图像,当悬停时将显示一个 DataBound 值。

下面是我的 ItemTemplate 代码:

<ItemTemplate> 

    <p> 
        <%# Eval("Name")%>
        &nbsp;&nbsp;
        <asp:Image ID="imgInfo" runat="server" 
                   align="right" 
                   ImageUrl="~/App_Themes/Default/images/question.png" />
    </p> 

    <asp:TextBox ID="txtValue" runat="server" 
                 TextMode="MultiLine" 
                 Rows="4" 
                 SkinID="dummy" 
                 Text='<%# Bind("Value") %>' />

    <asp:Label ID="lblHelpText" runat="server" 
               Text='<%# Eval("HelpText")%>'  
               Visible="false" />

    <script language="javascript" type="text/javascript"> 

        $('[#ContentPlaceHolder1_lvStep1_imgInfo_0]').qtip({ 

            content: 'the tooltip text, I want text of lblHelpText here', 
            style: { name: 'blue' } 

        });

    </script> 

</ItemTemplate>

我的问题:

  1. 这样 Id 就很难了 编码,因此仅适用于一项。我 找不到一个选择器 为我选择 Id。

  2. 我需要 lblHelpText.Text 或 <%# Eval("帮助文本")%>作为 工具提示文本(内容:)

  3. 由于脚本位于 ItemTemplate,它将被创建为 项目数量的许多倍。是 有一种方法可以实现这一切 通过将脚本放在一处 (在 ItemTemplate 之外)?

,我们将非常感谢您的帮助

阿里

I am trying to use qTip inside an ASP.NET ListView. The page uses a MasterPage. There is an Image in each Item which will show a DataBound value when hovered.

Below is my ItemTemplate code:

<ItemTemplate> 

    <p> 
        <%# Eval("Name")%>
          
        <asp:Image ID="imgInfo" runat="server" 
                   align="right" 
                   ImageUrl="~/App_Themes/Default/images/question.png" />
    </p> 

    <asp:TextBox ID="txtValue" runat="server" 
                 TextMode="MultiLine" 
                 Rows="4" 
                 SkinID="dummy" 
                 Text='<%# Bind("Value") %>' />

    <asp:Label ID="lblHelpText" runat="server" 
               Text='<%# Eval("HelpText")%>'  
               Visible="false" />

    <script language="javascript" type="text/javascript"> 

        $('[#ContentPlaceHolder1_lvStep1_imgInfo_0]').qtip({ 

            content: 'the tooltip text, I want text of lblHelpText here', 
            style: { name: 'blue' } 

        });

    </script> 

</ItemTemplate>

My Questions:

  1. This way the Id has been hard
    coded, so works just on one item. I
    could not find a selector that would
    select the Ids for me.

  2. I need the lblHelpText.Text or
    <%# Eval("HelpText")%> as the
    tooltip text (content : )

  3. Since the script is within the
    ItemTemplate, it would be created as
    many times the number of items. Is
    there a way I can achieve all this
    by having script at one place
    (outside ItemTemplate)?

Your help will be most appreciated,

Ali

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半暖夏伤 2024-11-14 05:37:21

您可以在列表视图之外执行此操作,但需要重构您的设计;您需要一个全局 HTML 元素来包装整个项目,例如:

<div class='ItemContainer'>
  .
  .
</div>

并重构您的脚本:

$("#<%= listview.ClientID %>").find("<div.ItemContainer").each(function(i) {
   var img = $(this).find("img:first");
   //give the label a CSS class of.HelpText to make it easier to find
   var content = $(this).find("span.HelpText").html();

   $(img).qtip({ 

            content: content, 
            style: { name: 'blue' } 

        });
});

类似的东西。

HTH。

You could do it outside of the listview but you need to refactor your design; you need a global HTML element wrapping the entire item, such as:

<div class='ItemContainer'>
  .
  .
</div>

And refactor your script:

$("#<%= listview.ClientID %>").find("<div.ItemContainer").each(function(i) {
   var img = $(this).find("img:first");
   //give the label a CSS class of.HelpText to make it easier to find
   var content = $(this).find("span.HelpText").html();

   $(img).qtip({ 

            content: content, 
            style: { name: 'blue' } 

        });
});

Something like that.

HTH.

季末如歌 2024-11-14 05:37:21

您可以简单地为图像分配一个类,然后将帮助文本绑定到图像的标题属性中。

ItemTemplate:

<asp:Image ID="imgInfo" runat="server" 
    CssClass="listViewImage" align="right" 
    ImageUrl="~/App_Themes/Default/images/question.png" />

绑定:

((Image)MyListView.Controls.Find("imgInfo")).Title = HelpText;

如果您愿意,如果您不通过代码绑定,也可以在标记中执行此操作:

<asp:Image ID="imgInfo" runat="server" 
    CssClass="listViewImage" align="right" 
    Title='<%# Eval("HelpText")%>'
    ImageUrl="~/App_Themes/Default/images/question.png" />

qTip Init(如果默认情况下作为内容出现,qTip 使用标题标签):

$('img.listViewImage').qtip({
    style: { 
        name: 'blue'
    }
});

如果您不想使用标题标签,您可以使用“alt”或“rel”属性,其执行方式相同。或者,您可以将文本包含在隐藏元素中。这会更复杂一点,可能会这样做:

ItemTemplate:

<span class="listViewImage">
    <asp:Image ID="imgInfo" runat="server" 
        align="right" 
        ImageUrl="~/App_Themes/Default/images/question.png" />
    <span class="helpText" style="display: none;"><%# Eval("HelpText")%></span>
</span>

qTip Init (qTip use title tag if present as content by default):

$('span.listViewImage img').each(function() {
    $(this).qtip({
        content: $(this).find('span.helpText').html(),
        style: { 
            name: 'blue'
        }
    });
});

编辑:

忘记提及,使用这些解决方案,您可以将 JavaScript 移到外部您的项目模板。

You could simply assign a class to your images and then bind the help text into the title attribute of the image.

ItemTemplate:

<asp:Image ID="imgInfo" runat="server" 
    CssClass="listViewImage" align="right" 
    ImageUrl="~/App_Themes/Default/images/question.png" />

Binding:

((Image)MyListView.Controls.Find("imgInfo")).Title = HelpText;

You could also do this in your markup if you prefer if you're not binding via code:

<asp:Image ID="imgInfo" runat="server" 
    CssClass="listViewImage" align="right" 
    Title='<%# Eval("HelpText")%>'
    ImageUrl="~/App_Themes/Default/images/question.png" />

qTip Init (qTip uses title tag if present as content by default):

$('img.listViewImage').qtip({
    style: { 
        name: 'blue'
    }
});

If you don't want to use the title tag, you could use the "alt" or "rel" attribute, which would be performed the same way. Alternatively, you could contain the text in a hidden element. That'd be a bit more complex and might be done something like this:

ItemTemplate:

<span class="listViewImage">
    <asp:Image ID="imgInfo" runat="server" 
        align="right" 
        ImageUrl="~/App_Themes/Default/images/question.png" />
    <span class="helpText" style="display: none;"><%# Eval("HelpText")%></span>
</span>

qTip Init (qTip uses title tag if present as content by default):

$('span.listViewImage img').each(function() {
    $(this).qtip({
        content: $(this).find('span.helpText').html(),
        style: { 
            name: 'blue'
        }
    });
});

Edit:

Forgot to mention, with these solutions, you'd move the javascript outside of your item template.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文