jQuery对话框:在对话框上放置asp.net formview

时间:2014-01-25 04:45:53

标签: jquery dialog formview

我有一个简单的ASP.NET(VB)页面,我正在尝试做一些特定的事情: 在每次选择特定gridview记录时打开的对话框上放置一个asp.net formview。 / em>

这是症状:当我选择一条记录时,它会触发带有formview的对话框,但是当它应该包含在gridview中选择的记录时,formview是空的。

以下是我的问题:有谁能告诉我我错过了什么?我需要添加或执行哪些不同的操作,以便formview包含所选记录。

提前感谢任何有用的建议。

以下是定义对话框的相关jQuery代码:

$("[id$=div_fvEditRecord]").dialog({
autoOpen:false,
modal:true,
resizable: true                
});

以下是启动对话框的代码:

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select"  onclientclick="$(&quot;[id$=div_fvEditRecord]&quot;).dialog( &quot;open&quot;); return false;" Text="Select"></asp:LinkButton>

以下是包含对话框中的表单视图的div:

<div id="div_fvEditRecord" style="display:none">                
    <asp:FormView ID="fvEditRecord" runat="server" Caption="Edit selected record" 
        DataKeyNames="ID" DataSourceID="sdsTable_RandomStuff" DefaultMode="Edit" 
        EmptyDataText="No records have been chosen">
        <EditItemTemplate>
            ID:
            <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
            <br />
            Name:
            <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
            <br />
            Date:
            <asp:TextBox ID="txtDate_add" runat="server" Text='<%# Bind("Date") %>' />
            <br />
            Time:
            <asp:TextBox ID="txtTime_add" runat="server" Text='<%# Bind("Time") %>' />
            <br />
            Count:
            <asp:TextBox ID="CountTextBox" runat="server" Text='<%# Bind("Count") %>' />
            <br />
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
    </asp:FormView>
</div>

为了更好地了解上下文,这里是完整的asp.net文件。

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Private Sub UpdateViews(ByVal sender As Object, ByVal e As System.EventArgs) Handles fvEditRecord.ItemInserted
        gvViewRecords.DataBind()
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Dialog Form Test</title>
    <script src="Scripts/jquery-2.1.0.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.10.4.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery.timepicker.min.js" type="text/javascript"></script>

    <link href="Content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="Content/themes/base/jquery.ui.datepicker.css" rel="stylesheet" type="text/css" />
    <link href="Content/themes/base/jquery.ui.slider.css" rel="stylesheet" type="text/css" />   
    <link href="Scripts/jquery.timepicker.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        $(document).ready(function () {
            $("[id$=txtDate_add]").datepicker({
                dateFormat: "m/dd/yy",
                showAnim: "slide",
                changeMonth: true,
                changeYear: true
            });

            $("[id$=txtTime_add]").timepicker({
                scrollDefaultNow: true
            });

            $("[id$=div_fvEditRecord]").dialog({
                autoOpen:false,
                modal:true,
                resizable: true                
            });           
        });

  </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:sqldatasource ID="sdsTable_RandomStuff" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Sandbox1ConnectionString %>" 
        OldValuesParameterFormatString="original_{0}" 

        SelectCommand="SELECT [ID], [Name], [Date], [Time], [Count] FROM [RandomStuff] WHERE ([ID] = @ID)">
        <SelectParameters>
            <asp:ControlParameter ControlID="gvViewRecords" Name="ID" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:sqldatasource>
    <asp:SqlDataSource ID="sdsView_RandomStuff" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Sandbox1ConnectionString %>" 
        SelectCommand="SELECT * FROM [RandomStuff]" 
        ConflictDetection="CompareAllValues" 
        DeleteCommand="DELETE FROM [RandomStuff] WHERE [ID] = @original_ID AND (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND (([Date] = @original_Date) OR ([Date] IS NULL AND @original_Date IS NULL)) AND (([Time] = @original_Time) OR ([Time] IS NULL AND @original_Time IS NULL)) AND (([Count] = @original_Count) OR ([Count] IS NULL AND @original_Count IS NULL))" 
        InsertCommand="INSERT INTO [RandomStuff] ([Name], [Date], [Time], [Count]) VALUES (@Name, @Date, @Time, @Count)" 
        OldValuesParameterFormatString="original_{0}" 
        UpdateCommand="UPDATE [RandomStuff] SET [Name] = @Name, [Date] = @Date, [Time] = @Time, [Count] = @Count WHERE [ID] = @original_ID AND (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND (([Date] = @original_Date) OR ([Date] IS NULL AND @original_Date IS NULL)) AND (([Time] = @original_Time) OR ([Time] IS NULL AND @original_Time IS NULL)) AND (([Count] = @original_Count) OR ([Count] IS NULL AND @original_Count IS NULL))">
        <DeleteParameters>
            <asp:Parameter Name="original_ID" Type="Int32" />
            <asp:Parameter Name="original_Name" Type="String" />
            <asp:Parameter DbType="Date" Name="original_Date" />
            <asp:Parameter Name="original_Time" Type="DateTime" />
            <asp:Parameter Name="original_Count" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter DbType="Date" Name="Date" />
            <asp:Parameter Name="Time" Type="DateTime" />
            <asp:Parameter Name="Count" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter DbType="Date" Name="Date" />
            <asp:Parameter Name="Time" Type="DateTime" />
            <asp:Parameter Name="Count" Type="Int32" />
            <asp:Parameter Name="original_ID" Type="Int32" />
            <asp:Parameter Name="original_Name" Type="String" />
            <asp:Parameter DbType="Date" Name="original_Date" />
            <asp:Parameter Name="original_Time" Type="DateTime" />
            <asp:Parameter Name="original_Count" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

    <h1>
            jQuery Skill Development</h1>
        <ul>
            <li>Use Datepicker on a textbox in Formview</li>
            <li>Use Timepicker on a textbox in Formview</li>
            <li>Place Formview on a Dialog for new entries</li>
        </ul>

        <asp:GridView ID="gvViewRecords" runat="server" AllowSorting="True" 
            AutoGenerateColumns="False" DataKeyNames="ID" 
            DataSourceID="sdsView_RandomStuff" Caption="View/Edit Records">
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                            CommandName="Select" 
                            onclientclick="$(&quot;[id$=div_fvEditRecord]&quot;).dialog( &quot;open&quot;); return false;" 
                            Text="Select"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Date" DataFormatString="{0:d}" HeaderText="Date" 
                    SortExpression="Date" />
                <asp:BoundField DataField="Time" DataFormatString="{0:t}" HeaderText="Time" 
                    SortExpression="Time" />
                <asp:BoundField DataField="Count" HeaderText="Count" SortExpression="Count" />
            </Columns>
        </asp:GridView>
    <div id="div_fvEditRecord" style="display:none">                
        <asp:FormView ID="fvEditRecord" runat="server" Caption="Edit selected record" 
            DataKeyNames="ID" DataSourceID="sdsTable_RandomStuff" DefaultMode="Edit" 
            EmptyDataText="No records have been chosen">
            <EditItemTemplate>
                ID:
                <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
                <br />
                Name:
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Date:
                <asp:TextBox ID="txtDate_add" runat="server" Text='<%# Bind("Date") %>' />
                <br />
                Time:
                <asp:TextBox ID="txtTime_add" runat="server" Text='<%# Bind("Time") %>' />
                <br />
                Count:
                <asp:TextBox ID="CountTextBox" runat="server" Text='<%# Bind("Count") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
        </asp:FormView>
    </div>
    </form>
</body>
</html>

3 个答案:

答案 0 :(得分:0)

我认为这是因为

中的dsplay:none属性
<div id="div_fvEditRecord" style="display:none">

尝试删除它

答案 1 :(得分:0)

我希望这个

$("[id$=div_fvEditRecord]") 

应替换为

  $("[id$='div_fvEditRecord']") or $("#div_fvEditRecord")

答案 2 :(得分:0)

我改变了打开对话框的方式:通过head脚本块中定义的单独函数而不是gridview的onClientClick属性。

    $(document).ready( function Load_FV_Dialog() { 
       $("[id$=div_fvEditRecord]").dialog("open"); 
       return false; 
    });

我通过调用“Load_FV_Dialog()”调用onClientClick中的gridview中的函数,而不是让onClientClick =函数定义。

我要求帮助的问题现已解决:当我选择要编辑的记录时,对话框会显示所选行的表单视图。

但是,当我单击update时,会发送null值而不是更新的值。然而,这是我需要研究的另一个问题。感谢那些回复的人,他们帮助我考虑了我自己可能没想过的选择。