Wednesday, February 4, 2009
AJAX GridView paging Cutting Edge
C# Code copy and paste....
protected void bindGridView()
{
string connectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ToString();
SqlConnection sqlCon = new SqlConnection(connectionString);
try
{
SqlCommand sqlCmd = new SqlCommand("select * from products", sqlCon);
sqlCmd.CommandType = CommandType.Text;
SqlDataAdapter sqlAdp = new SqlDataAdapter(sqlCmd);
DataSet myDataSet = new DataSet();
sqlAdp.Fill(myDataSet);
// Delay the current Thread to display
// the UpdateProgress status
// Not required in real projects
System.Threading.Thread.Sleep(4000);
GridView1.DataSource = myDataSet;
GridView1.DataBind();
}
catch (Exception ex)
{
lblErrorMsg.Text = ex.Message;
}
}
protected void btnLoadData_Click(object sender, EventArgs e)
{
bindGridView();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindGridView();
}
Note: i was trying to execute this using PageIndex Changed . instead use PageIndexChanging.. paging works fine.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment