我一直在努力尝试将 ASP.NET Gridview 链接到 JQuery Mobile 对话框,该对话框将用于编辑 Gridview
中的数据。 .
我的目标是使用 GridView
来显示数据。用户单击一行,对话框将打开一个带有 FormView
的对话框。 ,用户可以编辑所选行的数据。我让它在 JQuery UI 对话框中正常工作,但是当我切换到 Jquery Mobile 时,事情就崩溃了。
现在,如果我在 iOS 设备或 Blackberry 上运行该对话框,该对话框会在屏幕上闪烁一秒钟。如果我在 Windows 中运行它,它可以正常工作。我不确定我做错了什么。
这是我的 aspx 页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyTest.aspx.cs" Inherits="MySite.MyTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
<style type="text/css">
.hover
{
background-color: Gray;
}
</style>
<script type="text/javascript">
function clickRow() {
//Had to put in $(document).ready or I got PostBack errors.
$(document).ready(function () {
$.mobile.changePage("#dialogPage", 'pop', true, true);
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div data-role="page" id="mainpage">
<div data-role="content">
...GridView goes here...
<a href="#dialogPage" id="lnkDialog" data-rel="dialog">Click Me</a>
</div>
</div>
<div data-role="dialog" id="dialogPage">
<div data-role="content">
... FormView goes here....
</div>
</form>
</body>
</html>
下面是一些背后的代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Allows user to click/tap anywhere on gridview row to trigger SelectIndexChange
e.Row.Attributes["onmouseover"] = "this.oldClass = this.className;this.className='hover';";
e.Row.Attributes["onmouseout"] = "this.className=this.oldClass;";
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(GridView1, "Select$" + e.Row.RowIndex.ToString());
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
//This should open dialog
ClientScript.RegisterStartupScript(typeof(Page), "test", "clickRow()",true);
}
我认为问题在于我包装
$.mobile.changePage()
的方式$(document).ready()
中的函数功能。如果我不这样做,我就会收到回发错误。我不确定这样做的正确方法。如果我尝试使用
<a data-rel="dialog"></a>
打开对话框链接,它在所有设备上都能正常工作。感谢您的任何建议。
最佳答案
我记得遇到过类似的情况。需要记住的是,在处理 jQuery mobile 时,位于 head 中的 script 标签不会加载到后续页面上。尝试将您的脚本块移动到用作页面的标记内。
关于带有 JQuery 移动对话框的 ASP.NET Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17076909/