Help in Automatic Paging in Datagrids and DateTime in Access
-
Well, I'm still quite lost and confused in the coding. Here's the code: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { if (Page.IsPostBack != true) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } } private void DataGridCatalog_SelectedIndexChanged(object sender, System.EventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } I don't think both functions are supposed to look the same, if I placed "DataGridCatalog.CurrentPageIndex = e.NewPageIndex;" in DataGridCatalog_SelectedIndexChanged then what do I put in for the PageChanger?
-
So that means I do not need the OnPageIndexChanged property to get it to work? I am very surprised at this. Here are the codes for the Page_Load event: public void Page_Load(object sender, System.EventArgs e) { if ((string)Session["LoginState"] == "yes") if (Page.IsPostBack != true) { //CatalogBindData(); OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); } } I cannot say enough thank yous for the help, Nick. :)
-
So that means I do not need the OnPageIndexChanged property to get it to work? I am very surprised at this. Here are the codes for the Page_Load event: public void Page_Load(object sender, System.EventArgs e) { if ((string)Session["LoginState"] == "yes") if (Page.IsPostBack != true) { //CatalogBindData(); OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); } } I cannot say enough thank yous for the help, Nick. :)
this must be executed each time. dont put it in an if statement OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); 1 line of code equals many bugs. So don't write any!!
-
So that means I do not need the OnPageIndexChanged property to get it to work? I am very surprised at this. Here are the codes for the Page_Load event: public void Page_Load(object sender, System.EventArgs e) { if ((string)Session["LoginState"] == "yes") if (Page.IsPostBack != true) { //CatalogBindData(); OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); } } I cannot say enough thank yous for the help, Nick. :)
private int Index = 0; public void Page_Load(object sender, System.EventArgs e) { if ((string)Session["LoginState"] == "yes") //CatalogBindData(); OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; // now set the current index if(!IsPostBack ) { if(! ViewState["Indexc"] ) Index = Convert.ToInt32( ViewState["Index"] ); else index = 0; DataGridCatalog.CurrentPageIndex = Index; } DataGridCatalog.DataBind(); objConnection.Close(); } your PageLoaD should look like so 1 line of code equals many bugs. So don't write any!!
-
So that means I do not need the OnPageIndexChanged property to get it to work? I am very surprised at this. Here are the codes for the Page_Load event: public void Page_Load(object sender, System.EventArgs e) { if ((string)Session["LoginState"] == "yes") if (Page.IsPostBack != true) { //CatalogBindData(); OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); } } I cannot say enough thank yous for the help, Nick. :)
private void DataGridCatalog_SelectedIndexChanged(object sender, System.EventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } This should look like so 1 line of code equals many bugs. So don't write any!!
-
private int Index = 0; public void Page_Load(object sender, System.EventArgs e) { if ((string)Session["LoginState"] == "yes") //CatalogBindData(); OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; // now set the current index if(!IsPostBack ) { if(! ViewState["Indexc"] ) Index = Convert.ToInt32( ViewState["Index"] ); else index = 0; DataGridCatalog.CurrentPageIndex = Index; } DataGridCatalog.DataBind(); objConnection.Close(); } your PageLoaD should look like so 1 line of code equals many bugs. So don't write any!!
Thanks, but I am still getting errors: It seems in the statement if(!ViewState["Indexc"] ), it says Operator ! cannot be applied to operand of type 'object'. And as said earlier, I can't place e.NewPageIndex in the DataGridCatalog_SelectedIndexChanged because it is System.EventArgs e. Any ideas? Thanks
-
Thanks, but I am still getting errors: It seems in the statement if(!ViewState["Indexc"] ), it says Operator ! cannot be applied to operand of type 'object'. And as said earlier, I can't place e.NewPageIndex in the DataGridCatalog_SelectedIndexChanged because it is System.EventArgs e. Any ideas? Thanks
first if( ViewState["Index"] == null ) will fix that Change the DataGridCatalog_Select... to private void DataGridCatalog_PageChanged( object sender. DataGridPageChangedEventArgs e ) that should fix everything SelectedIndexChanged is the default event. We dont want that event. We want the PageChanged event 1 line of code equals many bugs. So don't write any!!
-
private void DataGridCatalog_SelectedIndexChanged(object sender, System.EventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } This should look like so 1 line of code equals many bugs. So don't write any!!
Thanks for all the help. I just executed the program, there is no error messages, however, when I click on the "Next" button it simply refreshes and shows exactly the same contents as before, seems it isn't working. OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string SQLSessionString = (string)Session["SQLSessionString"]; string strSQL; string CatalogCategory; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = SQLSessionString + (string)Session["CatalogSortString"]; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; if(!IsPostBack ) { if( ViewState["Index"] == null ) { Index = Convert.ToInt32( ViewState["Index"] ); } else { Index = 0; } DataGridCatalog.CurrentPageIndex = Index; } DataGridCatalog.DataBind(); objConnection.Close(); and: private void DataGridCatalog_PageChanged( object sender, DataGridPageChangedEventArgs e ) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } What could I be missing??? Any clues? Thanks!
-
private void DataGridCatalog_SelectedIndexChanged(object sender, System.EventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } This should look like so 1 line of code equals many bugs. So don't write any!!
I think I just got it to work, Nick!!! It seems instead of using: private void DataGridCatalog_PageChanged( object sender, DataGridPageChangedEventArgs e ) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } I placed it in the PageChanger function instead. So it is like public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } After that I have placed the OnPageIndexChanged="PageChanger" in the Datagrid's opening tags. So far it seems to look fine, I am still testing it. In the meanwhile may I ask 2 simple questions? Is it possible to pass the data of a session variable via an URL in ASP.NET? and how do you align the text in a multilined textbox? I tried using
andbut they are displayed along with the text as well. THANKS NICK, YOU HAVE BEEN AN AWESOME HELP!!!
-
I think I just got it to work, Nick!!! It seems instead of using: private void DataGridCatalog_PageChanged( object sender, DataGridPageChangedEventArgs e ) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } I placed it in the PageChanger function instead. So it is like public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState["Index"] = e.NewPageIndex; DataGridCatalog.DataBind(); } After that I have placed the OnPageIndexChanged="PageChanger" in the Datagrid's opening tags. So far it seems to look fine, I am still testing it. In the meanwhile may I ask 2 simple questions? Is it possible to pass the data of a session variable via an URL in ASP.NET? and how do you align the text in a multilined textbox? I tried using
andbut they are displayed along with the text as well. THANKS NICK, YOU HAVE BEEN AN AWESOME HELP!!!
yeah response.redirect("myasppage.aspx?mySessionValue=1") or create a html input field and make it type "hidden" then store the value Either way works. But since its in the session just get it when you need it. I use the viewstate in the same way between postbacks. Nick 1 line of code equals many bugs. So don't write any!!