更新jquery对话框内的gridview(ASP.net c#)

时间:2012-04-20 07:35:29

标签: c# jquery asp.net gridview jquery-ui-dialog

有没有办法更新jquery对话框中的gridview?我有按钮功能,但gridview没有更新。以下是我的代码。

JS:

    <script type="text/javascript" language="javascript">

$(document).ready(function () {

    function BindEvents() {


        //alerts dialog
        $( "#pnlAlerts" ).dialog({            
            autoOpen: false,
            modal: true,
            width: 700,             
            open:function(){{
                $(this).parent().appendTo($("form:first"));
            }}

        });

        $('.openAlert').click(function () {        
            $( '#pnlAlerts' ).dialog( 'open' );
        });
          }

    BindEvents();

}); 

前端:

            <asp:Panel runat="server" ID="pnlAlerts" Visible="true" class="alert-dialog">

            <asp:UpdatePanel ID="updPanelAlert" runat="server" >
                <ContentTemplate>
                    <asp:Label id="lblDatabaseStatus" runat="server" CssClass="left found" />

                    <asp:Panel id="pnlAlert" Runat="Server" Visible="true">

                        <div id="table-search">
                            <asp:Button ID="btnDelete" runat="server" Text="Delete" CssClass="btn normal-btn left" onclick="btnDelete_Click"  />
                            &nbsp;&nbsp;<asp:Button ID="btnMark" runat="server" Text="Mark as Read" CssClass="btn normal-btn left" onclick="btnMark_Click"  />
                            <!-- Loader -->
                            <asp:UpdateProgress ID="updProgress" runat="server" AssociatedUpdatePanelID="updPanelAlert" class="loader" DisplayAfter="1">
                                <ProgressTemplate>
                                        <asp:Image ID="imgPleaseWait" runat="server" ImageUrl="~/images/pleasewait.gif" />
                                </ProgressTemplate>
                            </asp:UpdateProgress>

                            <div class="nip">
                            </div>
                            <br class="clear"/>
                        </div>
                        <asp:SqlDataSource ID="sqldsAlert" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:ABCDB %>" 
                            SelectCommand="sp_AlertsGet" SelectCommandType="StoredProcedure">
                            <SelectParameters>
                                <asp:ControlParameter  ControlID="lblUserID" Name="UserID" Type="String" Direction="Input" />
                                <asp:Parameter DefaultValue="null" Direction="InputOutput" Name="op_status" 
                                    Type="String" />
                            </SelectParameters>
                        </asp:SqlDataSource>
                        <asp:Panel id="pnlAlertGrid" runat="server" ScrollBars="Auto" EnableTheming="false">
                            <!-- Table data -->
                            <asp:GridView id="gvAlertGrid" runat="server"  CssClass="grid" 
                                GridLines="Vertical" DataKeyNames="AlertID" AutoGenerateColumns="False" 
                                width="100%" PageSize="50" Border="0" 
                                AllowPaging="True" AllowSorting="True" PagerSettings-Position="Bottom" 
                                DataSourceID="sqldsAlert">

                                <Columns>

                                    <asp:TemplateField HeaderText="AlertID" Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lblAlertID" Text='<%# Eval("AlertID")%>'  runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="&nbsp">
                                        <itemTemplate>
                                            <asp:CheckBox ID="cbDeleteMark" width="25px" Checked="false" runat="server" Enabled="True"/>
                                        </itemTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Subject" SortExpression="AlertSubject">
                                        <itemTemplate>
                                            <asp:Label ID="lblAlertSubject" Text='<%# Eval("AlertSubject")%>' ForeColor='<%# SetColor(Eval("ReadStatus"))%>' runat="server" />
                                        </itemTemplate>
                                    </asp:TemplateField>

                                    <asp:TemplateField HeaderText="Type" SortExpression="Priority">
                                        <itemTemplate>
                                            <asp:Label ID="lblPriority" Text='<%# Eval("Priority")%>' ForeColor='<%# SetPriorityColor(Eval("ReadStatus"), Eval("Priority"))%>' runat="server" />
                                        </itemTemplate>
                                    </asp:TemplateField>

                                    <asp:templatefield headertext="Received" SortExpression="Date">
                                        <itemtemplate>
                                          <asp:label id="lblDate" ForeColor='<%# SetColor(Eval("ReadStatus"))%>'
                                            text= '<%# String.Format("{0:dd/MM/yy}",Eval("[Date]")) %>'
                                            runat="server"/> 
                                        </itemtemplate>
                                        <ItemStyle HorizontalAlign="Center" />                          
                                    </asp:templatefield>

                                </columns>
                            </asp:GridView>
                        </asp:Panel>
                    </asp:Panel>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:Label runat="server" ID="lblUserID" Visible="false"></asp:Label>
        </asp:Panel>            

1 个答案:

答案 0 :(得分:2)

为了让GridView更新,您需要让页面触发回发或执行服务器端 在GridView上调用DataBind。

您可以尝试的另一个选项是在更新面板中添加隐藏按钮,然后调用:

__doPostBack('<%= Button.ClientID %>','');

这应刷新更新面板,从而刷新GridView。

你刚刚打开jquery并关闭面板“pnlAlerts”作为模态对话框。

如果要在GridView中编辑数据,则需要使用EditTemplates。

希望有所帮助。