通过使用计时器刷新gridview,模态弹出窗口将自动关闭

时间:2012-10-31 08:34:25

标签: asp.net

我在网格视图列中使用模态弹出窗口,其中网格视图使用计时器设置。

<asp:UpdatePanel ID="GridPanel" runat="server">
            <ContentTemplate>
             <asp:Timer ID="autorefresh" runat="server" Interval="5000" />
            <asp:GridView ID="SigmaGrid" runat="server" AutoGenerateColumns="False" 
            onrowcommand="SigmaGrid_RowCommand" CssClass="mGrid" PagerStyle-CssClass="pgr" 
                    AlternatingRowStyle-CssClass="alt" AllowPaging="True" 
                    onpageindexchanging="SigmaGrid_PageIndexChanging">
           <AlternatingRowStyle CssClass="alt" />
            <PagerStyle />
            <Columns>
                <asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">                    
                    <ItemTemplate>
                        <asp:LinkButton ID="FirstName" runat="server" Text='<% # Eval("FirstName") %>' CommandName="Select"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
                <PagerStyle CssClass="pgr" />
        </asp:GridView>


<asp:Panel ID="DtlsPanel" runat="server" BackColor="White" Height="400" Width="500px" >
     <table style="border: Solid 3px #626262; width: 100%; height: 100%"
                            cellpadding="0" cellspacing="0">
                     <tr style="background-color: #626262">
                                <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
                                    align="center">                                  
                                Records                                  
                                </td>
                     </tr>                        
                     <tr>
                                <td style="color: Black">
                                    First Name:
                                </td>
                                <td align="center" style="color: Black">        
                                <asp:Label ID="FNamelbl2" runat="server"></asp:Label>
                                </td>
                     </tr>
     </table>
     </asp:Panel>
       <asp:Button ID="btnPopUp" runat="server" Style="display: none" />

     <asp:ModalPopupExtender ID="DetailsPopUp1" runat="server" BackgroundCssClass="modalBackground"
                     TargetControlID="btnPopUp" PopupControlID="DtlsPanel" CancelControlID="btnCancel"
                     PopupDragHandleControlID="PopupHeader">
</asp:ModalPopupExtender>
    </ContentTemplate>   


 </asp:UpdatePanel>

代码

protected void SigmaGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
            LinkButton FirstName = (LinkButton)e.CommandSource;
            GridViewRow row = (GridViewRow)FirstName.NamingContainer;

            FNamelbl2.Text = FirstName.Text;

            this.DetailsPopUp1.Show();
        }
    }

问题

当我点击名字colunn时,我会弹出一个显示行的详细信息..因为我使用过计时器gridview会刷新并弹出窗口会自动关闭。

1 个答案:

答案 0 :(得分:0)

如果您使用带有回发的ModalPopupExtender,则应确保在代码隐藏中显示弹出窗口。因此,您可以使用它的方法Show

例如在页面或UserControl的PreRender

C#

protected void Page_PreRender(object sender, System.EventArgs e)
{
    if (this.Visible) {
        this.DetailsPopUp1.Show();
    }
}

VB.NET

Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
    If Me.Visible Then
        Me.DetailsPopUp1.Show()
    End If
End Sub