Saturday, March 24, 2012

My gridview is not update

Hi,

I have an update panel in my page which contain a grid view.

I need to refresh my page periodically. I am using Timer for that. Here is my code

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:TimerID="Timer1"runat="server"Interval="10000">

</asp:Timer>

...................

<asp:GridViewID="GridView1"runat="server"SkinId="SampleGridView"CssSelectorClass="PrettyGridView"

DataKeyNames="ID"DataSourceID="SqlDataSource2"OnSelectedIndexChanged="GridView1_SelectedIndexChanged"

OnRowCommand="VerDiagramRed"Width="666px"OnDataBound="GridView1_DataBound"AutoGenerateColumns="False">

<Columns>

<asp:CommandFieldShowSelectButton="True"SelectText="Routers"/>

<asp:BoundFieldDataField="ID"HeaderText="ID"InsertVisible="False"ReadOnly="True"

SortExpression="ID"/>

<asp:BoundFieldDataField="Nombre"HeaderText="Nombre"SortExpression="Nombre"/>

<asp:BoundFieldDataField="Lectura"HeaderText="Lectura"SortExpression="Lectura"/>

<asp:BoundFieldDataField="Errores"HeaderText="Errores"SortExpression="Errores"/>

<asp:BoundFieldDataField="Estado"HeaderText="Estado"SortExpression="Estado"/>

<asp:ButtonFieldButtonType="Image"CommandName="diagram"HeaderText="Plano"

Text="Diagrama"ImageUrl="~/images/diagrama1.jpg"/>

</Columns>

</asp:GridView>

</ContentTemplate></asp:UpdatePanel>

DataGrid is not refreshed. What am doing wrong?

Thank you

Hi!

Follow these steps and it should work:

- Take the Timer out of the UpdatePanel.
- Set the UpdatePanel's properties UpdateMode="Conditional" and ChildrenAsTriggers="false"
- Add a trigger to the UpdatePanel's triggers collection:

<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="OnTick" />
</Triggers>

Now, as you are doing something on OnSelectedIndexChanged and OnRowCommand, are you sure that you need the Timer at all? Is not enough to refresh the GridView on these events?

Anyway, don't forget to add triggers for each event you are handling.

Hope this helps,



You can use Timer Control & you can trigger it's OnTick event..

So that it will periodically refreshes the GridViewSmile


Thank you very much. I did what you said and it is working perfectly.

I need to do refresh periodically because the users needs to monitor the information in the gridview.

No comments:

Post a Comment