aylin_sk

aylin_sk

  • NA
  • 87
  • 0

sorting

Dec 20 2004 7:35 AM
Hi, In my datagrid I want my headers to sort the column when i click the hyperlink of the headers..But i cant..I put AllowSorting="True" and gave SortExpressions to my headers in my .aspx page..What is the problem?? This is my .aspx.cs page: private void Page_Load(object sender, System.EventArgs e) { if (Page.IsPostBack) return; this.ViewState.Add("_sortExpression", "PATIENT_NAME"); } private void search_Click(object sender, System.EventArgs e) { if (myDataGrid.CurrentPageIndex > 0) myDataGrid.CurrentPageIndex = 0; bindMyDataGrid(textSearchString.Text); } private void bindMyDataGrid(string searchString) { coreLpms.patients myPatients = new coreLpms.patients(); DataSet myDataSet = myPatients.getPatients(searchString); myDataGrid.DataSource = myDataSet; myDataGrid.DataBind(); labelRecordCount.Text = myDataSet.Tables[0].Rows.Count.ToString(); labelCurrIndex.Text = Convert.ToString((myDataGrid.CurrentPageIndex + 1)); labelPageCount.Text = myDataGrid.PageCount.ToString(); if (myDataSet.Tables[0].Rows.Count > 0) { firstPage.Enabled = true; previousPage.Enabled = true; nextPage.Enabled = true; lastPage.Enabled = true; } else { firstPage.Enabled = false; previousPage.Enabled = false; nextPage.Enabled = false; lastPage.Enabled = false; } } private void bindMyDataGrid(string searchString, string sortExpression) { coreLpms.patients myPatients = new coreLpms.patients(); DataView myDataView = new DataView(); DataSet myDataSet = myPatients.getPatients(searchString); myDataView = myDataSet.Tables[0].DefaultView; myDataView.Sort = sortExpression; myDataGrid.DataSource = myDataView; myDataGrid.DataBind(); labelCurrIndex.Text = Convert.ToString((myDataGrid.CurrentPageIndex + 1)); labelRecordCount.Text = myDataSet.Tables[0].Rows.Count.ToString(); } public void pagerButtonClick(object sender, System.EventArgs e) { switch(((LinkButton)sender).CommandArgument) { case "first": myDataGrid.CurrentPageIndex = 0; break; case "previous": if (myDataGrid.CurrentPageIndex > 0) myDataGrid.CurrentPageIndex -= 1; break; case "next": if (myDataGrid.CurrentPageIndex < (myDataGrid.PageCount - 1)) myDataGrid.CurrentPageIndex += 1; break; case "last": myDataGrid.CurrentPageIndex = myDataGrid.PageCount - 1; break; } bindMyDataGrid(textSearchString.Text, this.ViewState["_sortExpression"].ToString()); } private void myDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) { this.ViewState.Add("_sortExpression", e.SortExpression.ToString()); bindMyDataGrid(textSearchString.Text, e.SortExpression.ToString()); }