jQuery 选择器和 DataPager 不能共存! (ASP.NET)
我正在使用 ASP .NET ListView 和 MS SQL 数据库。我使用 ListView 来显示信息,在列表视图中,有一个超链接,可打开 jQuery 模态对话框中特定记录的编辑窗口。
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<LayoutTemplate>
<div id="itemPlaceholder" runat="server"> </div>
</LayoutTemplate>
<ItemTemplate>
<!--More Items -->
<a name="Link" href="EditItem.aspx?id=<%# Eval("articleid")%>">Edit</a>
<!--More Items -->
</ItemTemplate>
</asp:ListView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SQL-SELECT-STATEMENT">
</asp:SqlDataSource>
<div>
jQuery 的工作原理是获取每个名为“Link”的项目的链接并将其与对话框关联起来。
<script type="text/javascript">
$(document).ready(function() {
$("a[name=Link]").each(function() {
var $link = $(this);
var $dialog = $('<div></div>')
.load($link.attr('href'))
.dialog({
autoOpen: false,
title: "Edit Article",
width: 500,
height: 550
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
});
});
</script>
一切都按其应有的方式进行。以前可以一次性显示所有记录,但随着记录数量的增加,我需要一种分页解决方案。 DataPager 来救援!
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="5">
<Fields>
<asp:NextPreviousPagerField />
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
但现在 DataPager 的控件不起作用!我无法后退、前进或单击页码,因为它将在没有对话框的情况下打开 ListView 中第一个数据绑定项的 href(就像普通页面一样)。但是,如果我删除 jQuery 代码,分页将按其应有的方式工作,但我没有得到用于编辑的简洁模态对话框:(
有什么想法为什么这些不能彼此共存吗?提前感谢很多:)
更新:什么不起作用的是它们不能和平共处。如果我删除 jQuery 代码,DataPager 工作正常,但我将丢失用于编辑的模式对话框。如果我放回 jQuery 代码,模式对话框可以正常工作,但 DataPager 却不能:(
I am using a ASP .NET ListView with a MS SQL Database. I use the ListView to show the information and in the list view, there is an hyperlink which opens the editing window for the specific record in a jQuery Modal Dialog Box.
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<LayoutTemplate>
<div id="itemPlaceholder" runat="server"> </div>
</LayoutTemplate>
<ItemTemplate>
<!--More Items -->
<a name="Link" href="EditItem.aspx?id=<%# Eval("articleid")%>">Edit</a>
<!--More Items -->
</ItemTemplate>
</asp:ListView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SQL-SELECT-STATEMENT">
</asp:SqlDataSource>
<div>
And jQuery works by taking the link of each item which has the name "Link" and associating it with a dialog box.
<script type="text/javascript">
$(document).ready(function() {
$("a[name=Link]").each(function() {
var $link = $(this);
var $dialog = $('<div></div>')
.load($link.attr('href'))
.dialog({
autoOpen: false,
title: "Edit Article",
width: 500,
height: 550
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
});
});
</script>
Everything worked as it should. Earlier all the records could be shown in one go but as the number of records grew, I needed a paging solution. DataPager for the rescue!
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="5">
<Fields>
<asp:NextPreviousPagerField />
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
But now the DataPager's controls are not working! I cannot go back,forward or click a page number as it will open the first data bound item's href in the ListView without a dialog box (Just like a normal page). But if i remove the jQuery code, the paging works as it should but I don't get the neat modal dialog box for my editing :(
Any ideas why these cannot exist with each other? Thanx a lot in advance :)
UPDATE: What doesn't work is that they cannot co-exist peacefully. If i remove the jQuery code, the DataPager works fine but I will lost my modal dialog box for editing. If i put the jQuery code back, the modal dialog box works fine but the DataPager doesn't :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是链接选择器可能正在选择数据分页器链接。
您可以尝试
$("a[name='Link']").each(..
注意属性值周围的单引号。或者,为什么不使用 id 或类选择器。例如:
和
My guess is that link selector is probably selecting data pager links.
You can try
$("a[name='Link']").each(..
note single quotes around attribute value.Alternately, why don't you use id or class selectors. For example:
and