locked
Problem with UpdatePanel GridView refresh RRS feed

  • Question

  • User-1244686676 posted

    Hi,
    I have to refresh automatically a GridView. I use an UpdatePanel control and a Timer control.

    This is my HTML code:

    <asp:Timer ID="TMROrdiniInviati" runat="server" Interval="15000"></asp:Timer>
    <asp:UpdatePanel ID="UPOrdiniInviati" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional" ViewStateMode="Enabled">
    	<ContentTemplate>                                                
    		<asp:GridView ID="GVOrdiniCorriereMG" runat="server" AutoGenerateColumns="False" BackColor="White" 
                                                            BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
                                                            DataSourceID="SDSOrdiniCorriereMG" 
                                                            DataKeyNames="IDOrdine" HorizontalAlign="Center" 
                                                            EmptyDataText="Nessun ordine inviato presente in archivio" Width="95%">
                                                            
    							........................
    							........................
    							........................
    
    
                    </asp:GridView>
                    <asp:SqlDataSource ID="SDSOrdiniCorriereMG" runat="server" ConnectionString="<%$ ConnectionStrings:AHR_PORTALE_sa_ConnectionString %>"                                 
    							........................
    							........................
    							........................                                                        
                    </asp:SqlDataSource>
    	</ContentTemplate>
    	<Triggers>
            	<asp:AsyncPostBackTrigger ControlID="TMROrdiniInviati" EventName="Tick" />        	
            </Triggers>
    </asp:UpdatePanel>

    And this is my code-behind code:

    Private Sub TMROrdiniInviati_Tick1(sender As Object, e As System.EventArgs) Handles TMROrdiniInviati.Tick
         GVOrdiniCorriereMG.DataBind()
    End Sub

    The GridView auto-refresh works fine every 15 seconds but I have a problem when I select a GridView row by clicking on a select column.

    When I click to select a GridView row, the SelectedIndexChanged event is raised when the next Timer tick event occours... so I have to wait 15 second before the selection action is executed.

    I have to refresh automatically the GridView but I have, also, to work with GridView rows normally...

    Thank you very much!

    Monday, November 17, 2014 10:48 AM

Answers

  • User61956409 posted

    Hi wizardforli,

    Thanks for your post.

    When I click to select a GridView row, the SelectedIndexChanged event is raised when the next Timer tick event occours... so I have to wait 15 second before the selection action is executed.

    As for your problem, you could stop the timer before executing selection action and restart it after selection action is executed as below.

    Protected Sub GVOrdiniCorriereMG_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GVOrdiniCorriereMG.SelectedIndexChanged
            'before executing selection action, set Timer.Enabled Property to false
            TMROrdiniInviati.Enabled = False
    
            ' your selection action
    
            'after executing selection action, set Timer.Enabled Property to true
            TMROrdiniInviati.Enabled = True
    
    End Sub
    

    Hope it will be helpful to you.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 18, 2014 1:25 AM