Help in Automatic Paging in Datagrids and DateTime in Access
-
I have 2 questions which is driving me nuts. It is about paging in a Datagrid. I am trying to do an automatic paging. I did the following: I set Allowpaging to TRUE, and AllowCustomPaging to FALSE In the Datagrid opening tag, I have set the command OnPageIndexChanged="PageChanger" And in the PageChanger command, it looks like this: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } Unfortunately everytime I execute the datagrid I get the following error message: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridCatalog when AllowPaging is set to true and the selected datasource does not implement ICollection. Exception Details: System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridCatalog when AllowPaging is set to true and the selected datasource does not implement ICollection. Source Error: NameofDatagrid.DataBind(); I tried setting Allowpaging to TRUE and AllowCustomPaging to TRUE, the datagrid is able to run, however, although it only shows the number of records I have set in the pagesize property, i.e, the previous and next buttons are unclickable. Is there anything else I should be doing? HELP!!! My next question involves extracting date/time format data from an Access 2003 Database. Everytime I extract a Date value from an Access Database and display it in a textbox, it is shown as 12/27/2005 00:00:00. How can I get rid of the time? This also applies when I am retrieving the time, it shows something like 12/31/1899 21:50:23. How can I get rid of the extra time/date? Is there a function to do that? THANKS!!!
-
I have 2 questions which is driving me nuts. It is about paging in a Datagrid. I am trying to do an automatic paging. I did the following: I set Allowpaging to TRUE, and AllowCustomPaging to FALSE In the Datagrid opening tag, I have set the command OnPageIndexChanged="PageChanger" And in the PageChanger command, it looks like this: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } Unfortunately everytime I execute the datagrid I get the following error message: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridCatalog when AllowPaging is set to true and the selected datasource does not implement ICollection. Exception Details: System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridCatalog when AllowPaging is set to true and the selected datasource does not implement ICollection. Source Error: NameofDatagrid.DataBind(); I tried setting Allowpaging to TRUE and AllowCustomPaging to TRUE, the datagrid is able to run, however, although it only shows the number of records I have set in the pagesize property, i.e, the previous and next buttons are unclickable. Is there anything else I should be doing? HELP!!! My next question involves extracting date/time format data from an Access 2003 Database. Everytime I extract a Date value from an Access Database and display it in a textbox, it is shown as 12/27/2005 00:00:00. How can I get rid of the time? This also applies when I am retrieving the time, it shows something like 12/31/1899 21:50:23. How can I get rid of the extra time/date? Is there a function to do that? THANKS!!!
-
I have 2 questions which is driving me nuts. It is about paging in a Datagrid. I am trying to do an automatic paging. I did the following: I set Allowpaging to TRUE, and AllowCustomPaging to FALSE In the Datagrid opening tag, I have set the command OnPageIndexChanged="PageChanger" And in the PageChanger command, it looks like this: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } Unfortunately everytime I execute the datagrid I get the following error message: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridCatalog when AllowPaging is set to true and the selected datasource does not implement ICollection. Exception Details: System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridCatalog when AllowPaging is set to true and the selected datasource does not implement ICollection. Source Error: NameofDatagrid.DataBind(); I tried setting Allowpaging to TRUE and AllowCustomPaging to TRUE, the datagrid is able to run, however, although it only shows the number of records I have set in the pagesize property, i.e, the previous and next buttons are unclickable. Is there anything else I should be doing? HELP!!! My next question involves extracting date/time format data from an Access 2003 Database. Everytime I extract a Date value from an Access Database and display it in a textbox, it is shown as 12/27/2005 00:00:00. How can I get rid of the time? This also applies when I am retrieving the time, it shows something like 12/31/1899 21:50:23. How can I get rid of the extra time/date? Is there a function to do that? THANKS!!!
The problem is what Ista mentioned. But if your hands are tied and cannot change the datasource, then the following article will help you: "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridID when AllowPaging is set to true and the selected datasource does not implement ICollection." [^] ...Though, it would we a lot easier to just change the datasource regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
-
The problem is what Ista mentioned. But if your hands are tied and cannot change the datasource, then the following article will help you: "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGridID when AllowPaging is set to true and the selected datasource does not implement ICollection." [^] ...Though, it would we a lot easier to just change the datasource regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
I wasn't meaning to change the datasource. The problem is he is linking to a class that doesn't implement the IList interface at the very least Akthough CollectionBase is the best alternative if you want to use an ArrayList;P And the reason it must implement the ICollection interface is because you MUST tell the grid what is happening with the data source. Akthough Implementing the ICollection interface is more annoying than the IList interface and its much easier just inheriting the CollectionBase class But be forewarned there are about 10 methods you must implement to have this work correctly. And the document from MSDN IS NOT CORRECT!!! You will find this out on your own however:mad: 1 line of code equals many bugs. So don't write any!! -- modified at 18:43 Wednesday 28th December, 2005
-
So what does this data source look like? Thats your problem If its a class then implement IList like it says. You can get away with IEnumerable but you would have to extend that datagrid Nick 1 line of code equals many bugs. So don't write any!!
Thanks for the reply, Ista, unfortunately I'm a newbie and I'm lost....big time. Is the following what you are looking for? OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string strSQL; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = "SELECT title, price, photo1 FROM Notebook "; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); OleDbDataReader myReader; myReader = objCommand.ExecuteReader(); DataGridCatalog.DataSource = myReader; DataGridCatalog.DataBind(); myReader.Close(); objConnection.Close(); I've heard somewhere that it is not possible to use DbDataReader, is the correct, is there any modifications to the code that I can do? Thanks for looking!!! I really appreciate it.
-
So what does this data source look like? Thats your problem If its a class then implement IList like it says. You can get away with IEnumerable but you would have to extend that datagrid Nick 1 line of code equals many bugs. So don't write any!!
Thanks for the reply, may I know if it is possible to convert a datareader to a dataset? The original code is as follows: strSQL = "SELECT title, price, photo1 FROM Notebook "; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strSQL, objConnection); /OleDbDataReader myReader; objConnection.Open(); myReader = objCommand.ExecuteReader(); DataGridCatalog.DataSource = myReader; DataGridCatalog.DataBind(); myReader.Close(); objConnection.Close(); And I changed it to something like this: strSQL = "SELECT title, price, photo1 FROM Notebook "; objConnection = new OleDbConnection(strConnect); OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strSQL, objConnection); objConnection.Open(); DataSet catalog = new DataSet(); objDataAdapter.Fill(catalog, "notebook"); DataGridCatalog.DataBind(); objConnection.Close(); Everything else is unchanged. The program executes all right with no error messages, but nothing is shown at all, i.e, the datagrid is not appearing at all. I guess it is not that simple eh, I just hope it is not an extremely complicated task? THANKS
-
Thanks for the reply, Ista, unfortunately I'm a newbie and I'm lost....big time. Is the following what you are looking for? OleDbConnection objConnection; OleDbCommand objCommand; string strConnect; string strSQL; strConnect = @"Provider=Microsoft.Jet.OLEDB.4.0;"; strConnect += @"Data Source = D:\Database\"; strConnect += @"Catalog.mdb ;"; strSQL = "SELECT title, price, photo1 FROM Notebook "; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); objConnection.Open(); OleDbDataReader myReader; myReader = objCommand.ExecuteReader(); DataGridCatalog.DataSource = myReader; DataGridCatalog.DataBind(); myReader.Close(); objConnection.Close(); I've heard somewhere that it is not possible to use DbDataReader, is the correct, is there any modifications to the code that I can do? Thanks for looking!!! I really appreciate it.
Yeah I have never seen it done, and frankly it doesn;t make sense. I mean the data source is a static entitity for a pass though. A datagrid must manuever the data so deleting it is like playing baseball and erasing home plate. How are you going to score without it? There maybe an an underlying way, but I don't do it. If you found a way how much hair would the next programmer have after looking at your code? none. Set the data source to a collection or a DataTable Then your error will disappear I believe the code is DataTable tdTable = new DataTable("MyTable"); OleDataAdapter adapter = new OldDataAdapter(objCommand); adapter.Fill(dtTable); DataGridCatalog.DataSource = dtTable.DefaultView; I could show code with the reader, but I don't believe in steering people down the wrong path. sry Nick 1 line of code equals many bugs. So don't write any!!
-
Thanks for the reply, may I know if it is possible to convert a datareader to a dataset? The original code is as follows: strSQL = "SELECT title, price, photo1 FROM Notebook "; objConnection = new OleDbConnection(strConnect); objCommand = new OleDbCommand(strSQL, objConnection); OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strSQL, objConnection); /OleDbDataReader myReader; objConnection.Open(); myReader = objCommand.ExecuteReader(); DataGridCatalog.DataSource = myReader; DataGridCatalog.DataBind(); myReader.Close(); objConnection.Close(); And I changed it to something like this: strSQL = "SELECT title, price, photo1 FROM Notebook "; objConnection = new OleDbConnection(strConnect); OleDbDataAdapter objDataAdapter = new OleDbDataAdapter(strSQL, objConnection); objConnection.Open(); DataSet catalog = new DataSet(); objDataAdapter.Fill(catalog, "notebook"); DataGridCatalog.DataBind(); objConnection.Close(); Everything else is unchanged. The program executes all right with no error messages, but nothing is shown at all, i.e, the datagrid is not appearing at all. I guess it is not that simple eh, I just hope it is not an extremely complicated task? THANKS
your getting there To be honest a DataSet is just a collection of IList interfaces get rid of the DataSet, it eats memory change the fill to objDataAdapter.Fill(dtNotebookTable); Here I am popultaing the DataTable directly then set the data source to the DataTables default view Why not the DataTable. Because you never hit it directly. So either attach to the DefaultView or create your Own view frim it. The DataView has a lot of customization methods to it also so you can make the data appear sorted among other things Nick 1 line of code equals many bugs. So don't write any!!
-
Yeah I have never seen it done, and frankly it doesn;t make sense. I mean the data source is a static entitity for a pass though. A datagrid must manuever the data so deleting it is like playing baseball and erasing home plate. How are you going to score without it? There maybe an an underlying way, but I don't do it. If you found a way how much hair would the next programmer have after looking at your code? none. Set the data source to a collection or a DataTable Then your error will disappear I believe the code is DataTable tdTable = new DataTable("MyTable"); OleDataAdapter adapter = new OldDataAdapter(objCommand); adapter.Fill(dtTable); DataGridCatalog.DataSource = dtTable.DefaultView; I could show code with the reader, but I don't believe in steering people down the wrong path. sry Nick 1 line of code equals many bugs. So don't write any!!
Thanks for the quick reply, Ista. Here is what I have modified the code to: objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); The good news is that the datagrid is finally loading and displays the contents in the datagrid, the Previous and next buttons are also clickable, however, the bad news is when I clicked "next" it simply does not show the datagrid at all. There is an OnPageIndexChanged="PageChanger in my Datagrid opening tag. And the codes inside PageChanger is as follows: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } My classmate said he used the codes above and it worked for him. What else should I be modifying? THANKS, Nick!!!
-
Thanks for the quick reply, Ista. Here is what I have modified the code to: objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); The good news is that the datagrid is finally loading and displays the contents in the datagrid, the Previous and next buttons are also clickable, however, the bad news is when I clicked "next" it simply does not show the datagrid at all. There is an OnPageIndexChanged="PageChanger in my Datagrid opening tag. And the codes inside PageChanger is as follows: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } My classmate said he used the codes above and it worked for him. What else should I be modifying? THANKS, Nick!!!
Explanation I forgot Every time you click the button it posts back So you must save the current index Then at post back set the current index Also, every postback reset the datasource and then rebind() If you extended the DataGrid you could change this behavior but lets keep it simple 1 line of code equals many bugs. So don't write any!!
-
Thanks for the quick reply, Ista. Here is what I have modified the code to: objConnection.Open(); DataTable CatalogTable = new DataTable("notebook"); OleDbDataAdapter Catalogadapter = new OleDbDataAdapter(objCommand); Catalogadapter.Fill(CatalogTable); DataGridCatalog.DataSource = CatalogTable.DefaultView; DataGridCatalog.DataBind(); objConnection.Close(); The good news is that the datagrid is finally loading and displays the contents in the datagrid, the Previous and next buttons are also clickable, however, the bad news is when I clicked "next" it simply does not show the datagrid at all. There is an OnPageIndexChanged="PageChanger in my Datagrid opening tag. And the codes inside PageChanger is as follows: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } My classmate said he used the codes above and it worked for him. What else should I be modifying? THANKS, Nick!!!
Set the current page index in the postback Dim iIndex as Int32 = 0 if( !postback ) if( not ViewState("Index") is nothing ) then iIndex = Convert.ToInt32( ViewState("Index") ) else iIndex = 0 DataGridCatakig.CurrentPageIndex = iIndex; end if My VB is rusty so there will be errors That should do it 1 line of code equals many bugs. So don't write any!!
-
Explanation I forgot Every time you click the button it posts back So you must save the current index Then at post back set the current index Also, every postback reset the datasource and then rebind() If you extended the DataGrid you could change this behavior but lets keep it simple 1 line of code equals many bugs. So don't write any!!
I hate to be a pest but where do you set this Postback thingy? Is it in the codes of the postback function? if (Page.IsPostBack != true) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } Or is it in the properties window is Visual Studio .NET 2003? I just can't seem to find anywhere with a postback property. Sorry about all these questions but I am hell not a pro with preogramming, thanks Nick.
-
I hate to be a pest but where do you set this Postback thingy? Is it in the codes of the postback function? if (Page.IsPostBack != true) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } Or is it in the properties window is Visual Studio .NET 2003? I just can't seem to find anywhere with a postback property. Sorry about all these questions but I am hell not a pro with preogramming, thanks Nick.
I slipped. Save the index value in the PageIndexChanged Handler(event) then set it in the postback also. goes in the handler DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState{"Index} = e.NewPageIndex; DataGridCatalog.DataBind(); every postback set the data source, grab the Index from the viewstate and set the current index 1 line of code equals many bugs. So don't write any!!
-
I slipped. Save the index value in the PageIndexChanged Handler(event) then set it in the postback also. goes in the handler DataGridCatalog.CurrentPageIndex = e.NewPageIndex; ViewState{"Index} = e.NewPageIndex; DataGridCatalog.DataBind(); every postback set the data source, grab the Index from the viewstate and set the current index 1 line of code equals many bugs. So don't write any!!
Thanks for the reply. From my understanding, is it something like this: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { if (Page.IsPostBack != true) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } } and private void DataGridCatalog_SelectedIndexChanged(object sender, System.EventArgs e) { if (Page.IsPostBack != true) { Save the index value in the PageIndexChanged Handler(event) } } What is the syntax for Saving the index value anyway? Sorry if these questions sound idiotic....I really am...:( -- modified at 22:19 Wednesday 28th December, 2005
-
Thanks for the reply. From my understanding, is it something like this: public void PageChanger(Object sender, DataGridPageChangedEventArgs e) { if (Page.IsPostBack != true) { DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); } } and private void DataGridCatalog_SelectedIndexChanged(object sender, System.EventArgs e) { if (Page.IsPostBack != true) { Save the index value in the PageIndexChanged Handler(event) } } What is the syntax for Saving the index value anyway? Sorry if these questions sound idiotic....I really am...:( -- modified at 22:19 Wednesday 28th December, 2005
Its my fault, I confused you In the DataGridCatalog_PageIndexChanged // Dont worry about the postback here DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); in the Page_Load // Postback only occurs here put the postback if statement I typed in the 2 answers up Then it will work. If it doesnt past those 2 code punctions in and I can look at then and see whats wrong 1 line of code equals many bugs. So don't write any!!
-
Its my fault, I confused you In the DataGridCatalog_PageIndexChanged // Dont worry about the postback here DataGridCatalog.CurrentPageIndex = e.NewPageIndex; DataGridCatalog.DataBind(); in the Page_Load // Postback only occurs here put the postback if statement I typed in the 2 answers up Then it will work. If it doesnt past those 2 code punctions in and I can look at then and see whats wrong 1 line of code equals many bugs. So don't write any!!
Thanks again, however it seems I am unable to place e.NewPageIndex in the DateGridCatalog, since it is System.EventArgs e, not DataGridPageChangedEventArgs e. Any ideas? Thanks
-
Thanks again, however it seems I am unable to place e.NewPageIndex in the DateGridCatalog, since it is System.EventArgs e, not DataGridPageChangedEventArgs e. Any ideas? Thanks
e.NewPageIndex is a property of DataGridPageChangedEventArgs you will set the DataGridCatalor.CurrentPageIndex with the value of e.NewPageIndex. does it give you an error? paste your code so I can make sure it looks correct. 1 line of code equals many bugs. So don't write any!!
-
e.NewPageIndex is a property of DataGridPageChangedEventArgs you will set the DataGridCatalor.CurrentPageIndex with the value of e.NewPageIndex. does it give you an error? paste your code so I can make sure it looks correct. 1 line of code equals many bugs. So don't write any!!
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?
-
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?
-
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?