aylin_sk

aylin_sk

  • NA
  • 87
  • 0

A serious problem, need to be solved urgently...

Dec 17 2004 10:10 AM
I have a problem while searching for a record..For example: In my search page I first search for the records which is including all the a's...When i passed to the next page and want to search the records including "b"s...But when I do that, I got an error like this: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. Source Error: Line 69: DataSet myDataSet = myPatients.getPatients(searchString); Line 70: myDataGrid.DataSource = myDataSet; Line 71: myDataGrid.DataBind(); Line 72: Line 73: labelRecordCount.Text = myDataSet.Tables[0].Rows.Count.ToString(); Source File: \\phtris-s3014\wwwroot$\lpms\searchpatient.aspx.cs Line: 71 Stack Trace: [HttpException (0x80004005): Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.] System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +2117 System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +49 System.Web.UI.WebControls.BaseDataList.DataBind() +23 lpms.searchPatient.bindMyDataGrid(String searchString) in \\phtris-s3014\wwwroot$\lpms\searchpatient.aspx.cs:71 lpms.searchPatient.search_Click(Object sender, EventArgs e) in \\phtris-s3014\wwwroot$\lpms\searchpatient.aspx.cs:62 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1277 ------------------------------------------------------------------------------------ This is all my code where I got an error: private void search_Click(object sender, System.EventArgs e) { 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); } private void myDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) { bindMyDataGrid(textSearchString.Text, e.SortExpression.ToString()); }

Answers (1)