ASP.NET Articles by Harish Ranganathan: ASP.NET DataGrid - Custom Paging using the Cache Object - Part II: "ASP.NET DataGrid - Custom Paging using the Cache Object - Part II This article is in continuation with the previous article on implementing Custom Paging for ASP.NET DataGrid using the Cache object. In case you have missed out the previous article, please check Part I Just to recall, we declared a DataGrid with AllowPaging='true' and set the PagerStyle-Visible='false'. Also, we declared a Panel with LinkButtons for First, Previous, Next and Last links for Paging and set a Command event for the link buttons 'NavigationLink_Click()'. We will examine the code for implementing paging. Global Variables used for Paging private int TotalPages; private int TotalRecords; private int CurrentPage; private int PageSize; Code for binding the Data to the DataGrid private void BindData() { SqlConnection objCon = new SqlConnection('your connection string goes here'); SqlCommand objCmd = new SqlCommand('select * from customers', objCon); DataSet dsNew = new DataSet(); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = objCmd; da.Fill(ds); Cache['AllRecords'] = ds; dsNew = (DataSet)Cache['AllRecords']; ViewState['TotalRecords'] = dsNew.Tables[0"
No comments:
Post a Comment