protected void PopulateGrid(object sender, EventArgs e) { var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["developmentserver"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlCommand fetchCommand = new SqlCommand("Select * from EMP where DEPTNO =" + DeptList.SelectedValue + "", conn); SqlDataReader reader = fetchCommand.ExecuteReader(); EmpGrid.DataSource = reader; EmpGrid.DataBind(); }
protected void Grid_PageIndexChanged(object source, DataGridPageChangedEventArgs e) { DataSet myDataSet = GetViewState(); DataTable myDataTable = myDataSet.Tables[0]; DataView _dataView = SortDataTable(myDataTable, true); EmpGrid.DataSource = _dataView; EmpGrid.CurrentPageIndex = e.NewPageIndex; EmpGrid.DataBind(); // Rebind the sorted data into ViewState DataTable dt = new DataTable(); DataSet ds = new DataSet(); dt = _dataView.ToTable(); ds.Merge(dt); SetViewState(ds); // Grid.CurrentPageIndex = e.NewPageIndex; // LoadDataList(); }
private void LoadDataList() { try { DataSet _DataList = null; if (ViewState["myDataSet"] == null) // No such value in view state, take appropriate action. { _DataList = DatabaseManager.Data.DBAccessManager.RetrieveEmployeeListByStatusMenu(-1, Int32.Parse(Page.User.Identity.Name.ToString())); if (_DataList.Tables[0].Rows.Count > 0) { this.EmpGrid.DataSource = _DataList; this.EmpGrid.DataBind(); emptyRow.Text = ""; emptyRow.Visible = false; SetViewState(_DataList); } else { this.EmpGrid.DataSource = null; this.EmpGrid.DataBind(); emptyRow.Visible = true; emptyRow.CssClass = "errorMessage"; emptyRow.Text = "There are no matching records found."; } } else // If it is avaiable in the viewstate bind it from there. { _DataList = GetViewState(); this.EmpGrid.DataSource = _DataList; this.EmpGrid.DataBind(); } } catch (Exception exception) { EmpGrid.CurrentPageIndex = 0; EmpGrid.DataBind(); } }