在 asp.net listview itemtemplate 中使用 qTip
我正在尝试在 ASP.NET ListView 中使用 qTip 。该页面使用 MasterPage。每个项目中有一个图像,当悬停时将显示一个 DataBound 值。
下面是我的 ItemTemplate 代码:
<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>
我的问题:
这样 Id 就很难了 编码,因此仅适用于一项。我 找不到一个选择器 为我选择 Id。
我需要 lblHelpText.Text 或 <%# Eval("帮助文本")%>作为 工具提示文本(内容:)
由于脚本位于 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:
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.I need the lblHelpText.Text or
<%# Eval("HelpText")%> as the
tooltip text (content : )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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在列表视图之外执行此操作,但需要重构您的设计;您需要一个全局 HTML 元素来包装整个项目,例如:
并重构您的脚本:
类似的东西。
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:
And refactor your script:
Something like that.
HTH.
您可以简单地为图像分配一个类,然后将帮助文本绑定到图像的标题属性中。
ItemTemplate:
绑定:
如果您愿意,如果您不通过代码绑定,也可以在标记中执行此操作:
qTip Init(如果默认情况下作为内容出现,qTip 使用标题标签):
如果您不想使用标题标签,您可以使用“alt”或“rel”属性,其执行方式相同。或者,您可以将文本包含在隐藏元素中。这会更复杂一点,可能会这样做:
ItemTemplate:
qTip Init (qTip use title tag if present as content by default):
编辑:
忘记提及,使用这些解决方案,您可以将 JavaScript 移到外部您的项目模板。
You could simply assign a class to your images and then bind the help text into the title attribute of the image.
ItemTemplate:
Binding:
You could also do this in your markup if you prefer if you're not binding via code:
qTip Init (qTip uses title tag if present as content by default):
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:
qTip Init (qTip uses title tag if present as content by default):
Edit:
Forgot to mention, with these solutions, you'd move the javascript outside of your item template.