I have a custom gridview on rowdatabound i am adding new gridviewrows . but on postback the data in newly added row is not persists. Please help me to maintain the state of grid on postback as well...Actually i m showing group header rows and footer rows and showing some calculated values in group footer row...but on post back the values of new group rows is not persists but the grid row is ther without values.
You're adding the rows dynamically so you have to populate the grid every time the page is posted back, not just if(!this.IsPostBack).
If you're not persisting to a db every post-back and generating the grid looping through some result-set coming from your db - you might have to store info about the temporary rows in ViewState. People will be able to help on this if you expand your question.
If you're populating dynamically and the data is coming straight from some db (or even State) every post-back you might wanna disable the grid viewstate (as in that case you're sending back and forth useless stuff).
Related
I populate a gridview from the db.
then i re arranged the rows in the gridview with javascript code.
i want to copy the rearranged gridview to a datatable
how it possible??
If you re-arranged your data using Javascript, you will have to update the database using Javascript. You will not be able to do if using server-side code.
Getting data and binding a GridView on the server-side and then rearranging it with Javascript is not a good idea. I suggest you either get your data purely from Javascript, or arrange your data on the server side before binding your GridView.
There could be multiple methods
First method
GridView row would have a hidden field in each row which should be updated with new row index and have a column for row index / order in database.
When user changes the row index of GridView Row, you will have to change the hidden fields of all effected with new rowindex. On server side you will have to iterate through the GridView rows and save the respective rows index / order in row column for order of row.
Second Method
You can send the changed rows index on each arrangement using the ajax (jquery ajax) and save the changed index in database row order column.
if you need to sort the gridview without reloading the page , then use an update panel enable and code for gridview pageindexchanging and sorting event , if you need any indication while processing use an updateprogress control .
If you are intended to update the data . then use ajax to send the data to a webmethod and update it into DB
I've one grid view which shows the current orders to supplier with the latest order at the top. Whenever customer places any order for that supplier, that order should be shown in the supplier grid view. For that I am refreshing the supplier order page every one minute so that the grid view get updated and will show the new orders if any.
But it will be rare that at every one minute a new order will be placed, so it makes no sense for me to refresh whole page every one minute. The only reason that I've given refresh interval of 1min is that it is necessary to display the orders to the suppliers as soon as they placed by customers.
What I want to do is that whenever a new row is inserted in my order table in db for particular supplier, I want to add the new row at the top to the grid view at client side with some animatio**n like masking that row with some colored overlay which fade out in some time. And this should be done **without refreshing the whole page.
I am not able to figure out how should I add new row to grid view whenever new row added to db without refreshing whole page.
You may try Nodejs and Socket to send/broadcast the message to clients every times successfully updated the table
You can probably use the update-method you are using for your page today, but then use a javascript solution to update only part of the page.
Take a look a these questions and answers for example, the should point you in the right direction even if they may not be a perfect fit for your problem:
Rebind gridview using AJAX (without post back)
update datagridview using ajax in my asp.net without refreshing the page.(Display real time data)
I'm trying to add some rows to a table control in my updatepanel. I have a button in update panel and when the button is clicked, partial postback happens, in button_click handler I add 1 row to the table. I can trigger the postback event and I am able to add 1 row each time, but the problem is that every time the page is postedback I got the initial table, meaning all the rows I've added in previous postbacks are gone, how can I solve this? Any ideas are welcome?
When you add rows in the table, you also need to save the struck of the table and somewhere else, for example on the view state, or on a database, or somewhere, and then recreate it because the code behind and the page it self did not have "a memory for what you do" on a table, did not know what you do on the DOM in general.
You may see the table on the page, but when you make a post back, the code behind did not get the post back of the struck of the table, only the posted data from input controls, so did not know by default what you have done on the table, and renders it from the beginning.
So, if you won to add rows in a table, and you won to remembers them on the next post back, save your struct also somewhere else, and when I say your struct, I do not mean all the table, you can simple save a number, eg how many rows you have add, or a number and an id, how many rows and what is on every row, and then before you add new rows, and on every post back, you recreate the table.
I'd like to get a grid with ability to add subheader (one or several rows) according to value of certain column (data source is grouped sorted by this column). Within my inherited GridView I override OnRowDataBind method: If value of considering column on current call of OnRowDataBind is not equal to previous values, then special header row is inserted before current row.
Table tbl = this.Controls[0] as Table; //this - pointer to CustomGridView
tbl.Controls.AddAt(rowIndex + add_counter + 1, NewSubHeaderRow); /*rowIndex - RowIndex of current row, add_counter - amount of already added SubHrader rows */
All works right. But problem occures on postback, when GridView restores it's state. First row and all its controls into every group (other words, first row after each dynamically added subheader row) comes without any attributes. But second row in group keeps both its own attributes and attributes of first row.
Some help will be very usefull. Maybe there is another (and right) way to add row into GridView. Then please, provide me with links to tutorials or articles.
Dynamic controls disappear on postback because on postback framework doesn't have information about such controls. It's programmer's responsibility to keep track of these dynamic controls and recreate them after postback...
Please refer to following post for re-creating dynamic controls on postback:
FAQ: Why do dynamic controls disappear on postback
Thanks for Waqas.
Here is my decision.
I override CreateChild(datasource, isBinding) and create list where put index of row, before which you should add subheader row. On SaveViewState i add this list to sealized object. On Load ViewState i load this list and if it's not null create subheader rows by saved indexes.
Maybe, there is a simpler and more natural way. But it's hidden from me securely )))
I'm trying to create an ASP.NET/C# page that allows the user to edit a table of data, add rows to it, and save the data back to the database. For the table of data, I'm using a DataGrid whose cells contain TextBoxes or CheckBoxes. I have a button for adding rows (which works) and a button for saving the data. However, I'm quite stuck on two things:
The TextBoxes and CheckBoxes should retain their values on postback. So if the user edits a TextBox and clicks the button to add more rows, the edits should be retained when the page reloads. However, the edits should not be saved to the database at this point.
When the user clicks the save button, or anytime before, the DataTable underlying the DataGrid needs to be updated with the values of the TextBoxes and CheckBoxes so that the DataTable can be sent to the database. I have a method that does this, but I can't figure out when to call it.
Any help getting this to work, or suggestions of alternative user interfaces that would behave similarly, would be appreciated.
Take a look at the ASP.NET GridView control. It's newer than the DataGrid and has editing features, editing events, etc built in.
Check out the following website:
http://highoncoding.com/Categories/7_GridView_Control.aspx
There are tons of articles on the above link about the GridView control.