asp.net adding row to a table in update panel - c#

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.

Related

Adding new row at the top in gridview whenever new row is inserted in database table at client side without refreshing whole page

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)

Editable, growable DataGrid that retains values on postback and updates underlying DataTable

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.

maintaining the state of Newly added row in custom gridview. on postback

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).

Moving to specific record within a DataTable

Hopefully simple, but can't find any such option.
I have a data table -- has say... 10 rows in it. Some fields on the form are bound to the table.columns respectively by name.
On another form that HAS a grid, as I scroll the grid, the detail fields are refreshed as expected since the grid does some magic to trigger the DataTable record changing event.
WITHOUT using a Data Grid, How can I direct the table to go to a specific row for load/display refresh on the form... ex:
DataTable MyTable = new DataTable();
MyTable = GetResultsFromSQL(); // returns the 10 rows
MyTable.LoadTheDataForRow(3);
MyTable.LoadTheDataForRow(7);
MyTable.LoadTheDataForRow(2);
I know I can use a foreach row in the table, but need explicit use as I don't want to go through all rows, but need specificity to specific ones.
I've looked at the LoadDataRow(), but that appears to be for pushing data back to a server. NOT what I want... I just want to have the "Current" row of the table to be of a specific one...
Thanks
After further research, I've found that a FORM based control "BindingSource" (or derivative) allows this, such as a grid. But, obviously, there's something the .Net engine is doing under the hood to ultimately "Load" a given row into something that ultimately triggers back to the "BindingSource"... The DataTable has RowChanging and RowChanged events which appear to be triggered by OnRowChanging / OnRowChanged delegates, but how can we tell the data table which "row" we want it as the active one.
The form controls can do this for their binding sources, but what is really happening under the hood to trigger these OnRowChanging events... I don't want to re-load a data table, rows, etc, just change what is considered the "Active" row, as in a grid, listbox, combobox, etc.
Have you tried:
MyDataTable.Rows[3];
MyDataTable.Rows[7];
MyDataTable.Rows[2];

Cleanest way to implement collapsable entries in a table generated via asp:Repeater?

Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of a very large system, so it really wouldn't be wise for me to revise the table structure (the app is filled with similar tables).
This is a webapp in C# .NET - data comes in from a webservice and is displayed onscreen in a table. The table's rows are generated with asp:Repeaters, so that the rows alternate colers nicely. The table previously held one item of data per row. Now, essentially, the table has sub-headers... The first row is the date, the second row shows a line of data, and all the next rows are data rows until data of a new date comes in, in which case there will be another sub-header row.
At first I thought I could cheat a little and do this pretty easily to keep the current repeater structure- I just need to feed some cells the empty string so that no data appears in them. Now, however, we're considering one of those +/- collapsers next to each date, so that they can collapse all the data. My mind immediately went to hiding rows when a button is pressed... but I don't know how to hide rows from the code behind unless the row has a unique id, and I'm not sure if you can do that with repeaters.
I hope I've expressed the problem well. I'm sure I'll find a way TBH but I just saw this site on slashdot and thought I'd give it a whirl :)
When you build the row in the databinding event, you can add in a unique identifier using say the id of the data field or something else that you use to make it unique.
Then you could use a client side method to expand collapse if you want to fill it with data in the beginning, toggling the style.display setting in Javascript for the table row element.
just wrap the contents of the item template in an asp:Panel, then you have you have a unique id. Then throw in some jquery for some spice ;)
edit: just noticed that you are using a table. put the id on the row. then toggle it.

Categories

Resources