使用asp:gridview在jquery模式对话框中添加新的行按钮

时间:2015-02-19 22:57:10

标签: jquery asp.net gridview

我有一个带有几个模板字段(用于下拉列表)的网格视图,如果我将它放在DIV之外,我将其用作模式对话框,它可以正常工作。 Grid具有onrowdatabound和OnRowDeleting事件,另外还有一个按钮,用于向网格添加新行。当我尝试将此网格移动到“模态”对话框时,“添加”按钮停止工作。 click事件在代码后面编码,并且不会触发。任何人都可以帮助我理解我应该如何处理它? 任何帮助将不胜感激。提前谢谢

<div id="dialog" >

<asp:GridView ID="grPlan" runat="server" 
            ShowFooter="True" 
            AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" 
            GridLines="None"
            onrowdatabound = "GridView_RowDataBound"
            OnRowDeleting = "GridView_RowDeleting" >
    <Columns>
        <asp:BoundField HeaderText="ID" DataField="id" />
        <asp:TemplateField HeaderText="Program>">
            <ItemTemplate >
                <asp:DropDownList ID="ddlProgModal2" runat="server" AppendDataBoundItems="true" AutoPostBack="false" DataTextField="Prog" 
    DataValueField="ProgID" />
            </ItemTemplate >
        </asp:TemplateField>
        <asp:TemplateField HeaderText="EF">
            <ItemTemplate >
                <asp:DropDownList ID="ddlAnneeFiscaleModal2"  DataTextField="EtendueLong" DataValueField="EtendueLong" runat="server" 
                AppendDataBoundItems="true" AutoPostBack="false"/>
            </ItemTemplate >
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Approbations">
            <ItemTemplate >
                <asp:DropDownList ID="ddlApprobationModal2" runat="server" AppendDataBoundItems="true" AutoPostBack="false" 
    DataTextField="Approb" DataValueField="ApprobationID"/>
            </ItemTemplate >
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Fonds">
            <ItemTemplate >
                <asp:TextBox ID="txtFondsModal2" runat="server" AutoPostBack="false" MaxLength="15" Width = "120" onkeypress="return 
    validateFloatKeyPress(this,event);" />
            </ItemTemplate >
            <FooterStyle HorizontalAlign="Right" />
            <FooterTemplate>
                <asp:Button ID="ButtonAdd" runat="server" Text="Add" OnClick="ButtonAdd_Click" />            
            </FooterTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowDeleteButton="True" />

    </Columns>
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <RowStyle BackColor="#EFF3FB" />
    <EditRowStyle BackColor="#2461BF" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="Black" />
    <AlternatingRowStyle BackColor="White" />

</asp:GridView>
</div>

$(&#34;#对话框&#34)。对话框({                     autoOpen:false,                     莫代尔:假的,                     宽度:600,                     身高:520,                     可调整大小:false,                     closeOnEscape:false,                     open:function(event,ui){                         //调试;                         $(&#34;的.ui-对话框的标题栏闭&#34)。隐藏();                         $(&#39; .ui-dialog&#39;)。css(&#34; left&#34;,&#34; 400px&#34;);                         $(&#39; .ui-dialog&#39;)。css(&#34; top&#34;,&#34; 300px&#34;);                         $(&#39; .ui-dialog&#39;)。css(&#34; position&#34;,&#34; absolute&#34;);                     },                     标题:&#39;&#39;,                     纽扣: {                         取消:function(){                             $(本).dialog(&#39;关闭&#39;);                         },                         &#39; OK&#39;:function(){                             $(本).dialog(&#39;关闭&#39;);                             返回true;                         }                     }                 });

1 个答案:

答案 0 :(得分:0)

有三种方法可以做你想做的事,

1)将gridview包裹在UpdatePanel内,然后将PostbackTrigger设置为添加按钮控件。

2)您可以使用gridview.RowCommand事件。它处理gridviewHere is more info on it

的单元格内所有与按钮相关的事件

3)您可以使用jquery使用postback Here is more info on it强制点击按钮__dopostback()