使用JQuery Mobile Dialog的ASP.NET Gridview

时间:2013-06-12 23:13:22

标签: asp.net jquery-mobile

我一直在努力尝试将ASP.NET Gridview链接到JQuery Mobile对话框,该对话框将用于编辑Gridview中的数据。

我的目标是使用GridView来显示数据。用户将单击一行,对话框将打开一个带有FormView的对话框,用户可以编辑所选行的数据。我使用JQuery UI对话框可以正常工作,但是当我切换到Jquery Mobile时,事情就崩溃了。

现在,如果我在iOS设备或黑莓手机上运行它,对话框会在屏幕上闪烁一秒钟。如果我在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>链接打开对话框,则可以在所有设备上正常使用。

感谢您的任何建议。

1 个答案:

答案 0 :(得分:0)

我记得遇到过类似的情况。要记住的是,在处理jQuery mobile时,位于头部内的脚本标签不会加载到后续页面上。尝试将脚本块移动到用作页面的标记内。