Sivakumar

Sivakumar

  • NA
  • 551
  • 210.1k

Gridview paging is not working correctly

Mar 22 2016 11:19 AM
Hi ,
 
I need pagination for my asp.net gridview 
 
 I write code like below but its not work correctly.
 
This is my c# code :
 
protected void Button1_Click(object sender, EventArgs e)
{
string url = "http://maps.google.com/maps/api/geocode/xml?address=" + txtsearch.Text + "&sensor=false";
WebRequest request = WebRequest.Create(url);
using (WebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
DataSet dsResult = new DataSet();
dsResult.ReadXml(reader);
DataTable dtCoordinates = new DataTable();
dtCoordinates.Columns.AddRange(new DataColumn[4] { new DataColumn("Id", typeof(int)),
new DataColumn("Address", typeof(string)),
new DataColumn("Latitude",typeof(string)),
new DataColumn("Longitude",typeof(string)) });
var latitude = string.Empty;
var longitude = string.Empty;
if (dsResult.Tables["location"] != null && dsResult.Tables["location"].Rows.Count > 0)
{
latitude = dsResult.Tables["location"].Rows[0]["lat"].ToString();
longitude = dsResult.Tables["location"].Rows[0]["lng"].ToString();
map.Lattitude = float.Parse(latitude);
map.Longitude = float.Parse(longitude);
map.Radius = float.Parse(txtdemo.Text);
dsLocation= mapBL.GetLocation(map);
GridView2.DataSource = dsLocation;
GridView2.DataBind();
}
}
}
}
 
 This is gridview onchange :
 
 
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
GridView2.DataSource = dsLocation;
GridView2.DataBind();
}
but this is not work properly
 
Please send correct code for that.
 
Thanks 

Answers (2)