468,554 Members | 1,891 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,554 developers. It's quick & easy.

Asp.net, Webservice, Ajax, Fetching data dynamically..


I have 2 Gridviews on my asp.net page. In this gridview i am showing list of links. I want to update these links dynamically after 5-10 seconds, without refreshing the page(without postbak) i want to fetch these link dynamically and want to bind it to Gridview..

I have little bit idea about this that. use the webservice to fetch record like we do it in Ajax AutoComplete. But how to fetch record dynamically and bind it to Gridview..

Please can anybody tell me steps to do that..


Yogesh Sapkale
May 15 '09 #1
3 4066
162 100+
ok fine.. i would just give an example of get data frm database and do databind . in C#

1. drag a GridView in the design page
2. declear the namespace in code behind page, call the Page_Load event

design page

Expand|Select|Wrap|Line Numbers
  2. drag a GridView
  4.  <asp:GridView ID="GridView1" runat="server">
  5.     </asp:GridView>
code behing page

declear namespace
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Globalization;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Web.UI.HtmlControls;
  15. public partial class Default2 : System.Web.UI.Page
  16. {
  17.     SqlConnection myConnection;
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.         // Make a connection to the database
  22.         myConnection = new SqlConnection("server=servername; Initial Catalog=database name; User ID=username; password=password");
  24.     // get the data frm database when page load
  25.         if (!IsPostBack)
  26.             BindGrid();
  28.     }
  30.     public void BindGrid()
  31.     {
  32.        SqlDataAdapter myCommand1 = new SqlDataAdapter("select * from tablename ", myConnection);
  35.         DataSet ds = new DataSet();
  36.        myCommand.Fill(ds, "tablename");
  38.         GridView1.DataSource = ds.Tables["tablename"].DefaultView;
  39.         GridView1.DataBind();
  40.         myCommand.Connection.Close();
  41.     }
  44. }
hope that gonna help you ...
May 15 '09 #2
But this code is Binding the GridView with PostBack, isn't it? Is there a way to bind using AJAX?
Aug 14 '09 #3
9,735 Expert Mod 8TB
When you use Ajax in .NET the whole page ASP page life cycle happens.

This means that if you place your GridView in an update panel and then use a Ajax Timer control to periodically cause an asynchronous post back to the page then everything server side is executed.

When the postback is sent down to the browser, the HTML is stripped down by .NET to only include what needs to be updated (which is within the UpdatePanel).

In my mind, it's sort of a .NET cheat. If you use pure Ajax, this is much different.

Anyways, just try adding an UpdatePanel to the page, and place the GridView in the UpdatePanel. Place a Timer control in the UpdatePanel and have it periodically cause an asynchronous postback to the server so that the GridView is refreshed (not the whole page).

Aug 17 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by peter.konda | last post: by
1 post views Thread by hesameagle | last post: by
2 posts views Thread by =?Utf-8?B?TW9oc2luIEtoYW4=?= | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.