Showing posts with label records. Show all posts
Showing posts with label records. Show all posts

Saturday, March 24, 2012

Load huge data in GridView using AJAX

Hi all

I need help in griview and ajax question, lets say I have a table wich contains about 100 000 records and I need load them into gridview but it takes too long, how can I load it row by row lets say first row is loaded and others show some "Loading... " message ans so on.

Thanks in advance.

One thing more, may be somebody knows how to hide an update panel when update progress is firing?

Hi,

Please refer to this sample:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>  </div> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </ContentTemplate> </asp:UpdatePanel> <asp:Button OnClientClick="" ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partialclass Default2 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) { Button1.OnClientClick ="document.getElementById('UpdatePanel1').style.display='none';"; BindData(); }static DataTable source;protected void BindData() {if (source ==null) { source =new DataTable(); source.Columns.Add("column 1"); source.Columns.Add("column 2"); } DataRow row = source.NewRow();// you can use datareader to get data from database here row[0] = DateTime.Now.ToString(); row[1] = DateTime.Now.ToString(); source.Rows.Add(row); GridView1.DataSource = source; GridView1.DataBind(); }protected void Button1_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(2000); }}

Please note here use nested UpdatePanel to achieve your second requirement of hide a panel.

Another thing you must pay attenation to is that such a function will cause a higher network traffic.

Hope this helps.

Wednesday, March 21, 2012

Loading with animation

Hey,

Because I need to load thousands of records on to GridView so when I access to this page, it takes about 20 seconds, I wonder that how can I implement it with Ajax that: an animation ( image) will be loaded at the center of my page, the rest of page will be silver, when the page is loaded successfully, animation will be disappeared and the page changed to white.

Anybody knows how to implement it, could you please help me?

Thanks,

Joesy

Hi,

you can use the UpdateProgress control or the PageRequestManager class. Take a look at the bottom of this page for an example:http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx.

Grz, Kris.


Hi Kris,

Thanks, I will try it.

Grz, Joesy


This may help.http://forums.asp.net/thread/1622218.aspx

It involves hiding or displaying a specific DIV until the page has loaded using the BODY tags onload event handler.

Here's another situation where it uses an UpdatePanel and an UpdateeProgress control:http://forums.asp.net/thread/1618788.aspx

Cheers,
Al


Hey Alharding,

Thanks for your advices,

Grz, Joesy