I have a editable nested repeater containing the data.I use it for showing the data and also for saving the data which is updated by the user.
I want to detect particular cell/row for which the data has been modified by the user so that I can update only that particular row in the database instead of saving all the data again.
Is there a way to work this out.Which would be the best technique to use ,Javascript or server side code ?
Resource country etc | Week1 Week2 Week3 | Total
ABC XYZ 10 15 20 45
This is the repeater structure.
Middle one (Weeks showing hours worked by resource which is editable) is the nested repeater.
Values can only be changed in the nested repeater.
I maintain unique ID's for each resource in the hidden field.
Can you suggest me some ways to achieve this functionlity ?
This is normally handled by your ORM, but you can implement it yourself if you like. The idea is called 'change tracking', and basically what's commonly done is to retrieve the record from the database, then compare known retrieve values to the new values before saving it again.
Depending on your concurrency strategy, you also might use a hash of the original values that were sent to the client, placed in a hidden field perhaps, which you can then check original vs. currently in the database in order to not accidentally overwrite someone else's changes.
Related
I have a datatable in code. And the datagridview in the Ui.
In code I have done gridviewName.DataSource = dtTable1
Now in the UI I can see gridview populated with the table data. In the UI gridview I can update the cell values and/or delete the data rows. Upon doing any changes to the gridview, the changes automatically flow back into the data table.
I am bit confused at this point because I had thought it is a 1 way connection from data table into datagridview. Is this 2 way by design? If yes, then subsequently if I want to perform an operation per row, like send an email per row, then it is recommended to iterate over the gridview or the data table?
Yes, the 2 way data flow is by design; it makes creating applications a lot easier. If you don't want your user to edit a grid you make the grid read only, but typically you show data to a user, you let them edit it and save it. That would get a lot more hard work if you made data binding a one way thing the grid is connected to the datatable directly; it doesn't copy the data it finds into its own internal data array
Always loop over the datatable, read it and edit it directly; the grid will update accordingly; always avoid looping over the datagridview. As the embodiment of model-View-controller your code should manipulate the model (datatable) not try and manipulate the model via the view/controller that is intended for the user (the datagridview)
If you add a DataSet type file to your project and design a strongly typed datatable inside it your life gets easier. Your code looks like:
foreach(var r in soneDataset.EmailQueueDataTable){
mailer.Send(r.From, r.To, r.Subject, r.Message, r.RetryAttempts);
}
With a standard datatable everything is done with string column names or worse, ordinal positions and needs casting:
foreach(DataRow r in EmailQueueDataTable.Rows){
mailer.Send((string)r["From"], (string)r["To"], (string)r["Sujbect"], (string)r["Message"], (int)r["RetryAttempts"]);
}
Intellisense won't help you with the column names either; you'll only find out at runtime that I made a typo in Subject
I am with a little issue on handling with one of my applications.
I have a Vessel's historic which is shown on a ListView, but until now I have never needed to show all the data inside this history (the user was using kind of a filter to get what he needed), but now one of the managers want to see all data through the application (they was receiving the full data through an excel report).
The biggest issue is because its 6000 rows with 21 columns each one and when I try to select all the data it takes something between 5 minutes to fully load, but more than that the user need to add new, edit or copy the history, which brings him to a new update on the list with more 5 minutes to load.
I don't quite know how is the best way to handle with this and I wanted your help!
I would actually split the information into sections. Rather than loading 6,000 rows plus columns all at once, why don't you use something like alphabetize the information? Use a different ListView for A-G, then another ListView for H-O, then so on and so forth. That why it would cut down the time it took to query all of the information.
So I'm reading data out of a database and want to display it on a webpage like this:
Name Age Fav# ...other info
Bob 11 15
Joe 13 4
I want to make a website that updates the contents of its table based on the database. I know the number of columns that the database has but not necessarily the number of rows.
I was thinking just writing the .aspx file and generating the HTML and values when the database is read, but I was looking at some similar stackoverflow questions and they advise against it? The suggestion was to create a template .aspx file and just populate it, but how would you do that if you don't know the exact number of rows to make?
Also if I programatically write my own Something.aspx files and create a Something.aspx.cs file, will they automatically link together?
I'm new to ASP.net and C#, so I'm not sure if there's an easier way of doing this.
Since you're using ASP.NET I'd suggest using GridView control to display table data. It has a lot more possibilities (like built in paging and sorting). And you do not need to know in advance number of rows - GridView will render whatever is thrown at it, turning on paging if nessesery
good day gurus!
I'm new to ASP.NET and I'm still in the process of learning it.
I was able to finish a couple of aspx pages through searching google but I can't seem to get this one page to work.
Basically, I'm trying to display a table (data fetched from SQL table).
All data are fetched from SQL table except for these static cells:
Item | Jan | Feb | March | April | Total
Sponge | Rod | Clock | Paper | Prod Cost | Profit
(and all the SUMS)
The "Adjust1" is inserted there if its values are not null. And this "Adjust1" also affects the "Total".
I hope someone can point me to the right direction.
Thanks a lot for your time,
Pod
use gridview template feild, just not bind data to your static feild
You can bind your dataset directly to a GrdiView control, and without much manipulation, it will output the columns and rows exactly like your dataset that you returned from the DB.
However, I'm not clear as to what you mean to do with the 'Adjust1' row. Can you explain this in a little more detail?
for the sql manipulation it will be much easier and clean, and create the dataset such a way that it look a like the gridview. This will be a more flexible approach as in future if you want to change any header say display January in place of Jan you dont need any new publish but just a sp update in database
I still you do not want to go with db you can any time achieve this task by using grid rowbound event. Add template fields for calculated columns like total, for displaying the header such jan,feb you can use the headertext property of bound field. For add the value in item field you can pass -1 in the dataset and while bound the grid based on the row index replace the text with required values.
for more details on row databound event read this http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx
I have a table Resource with a field Type. Type is a lookup into the table ResourceType.
So for instance ResourceType might have:
1: Books
2: Candy
3: Both
And Resource might have
1: Tom's Grocery, 2
2: Freds News, 3
It would display as: Tom's Grocery Candy
Now lets say I am using a databound combobox for the resource type and the third record is deleted from ResourceType, we of course get an error when Fred's News is displayed. I could simply put a marker in (perhaps an asterisk), indicating that it has been deleted, rather than actually delete it. It shows up as **Both* in the textbox portion of the combo and I am content.
However, I would not want it to show up as an option in the dropdown. Is this too much to ask from databound fields? Must I write my own code to load the drop down?
Add a bit Deleted column to the lookup table. When you delete a type, set Deleted = 1. When you pull back ResourceTypes, only pull out ResourceTypes where Deleted = 0 and then bind to the dropdown.
Edit:
How are you getting the dataset that you're binding to the dropdownlist? Are you using drag and drop datasets? I really haven't worked with datasets like that in years, but I'm pretty sure you can change the Get sql to what you need it to be.
OK, I already have most of that built into the solution - but I must be binding wrong. If I only pull back records where deleted = 0, I get exceptions - I'm guessing because the textbox can't be filled from the record set.
I guess I'm not sure how to bind the textbox display to one dataset - the one with all the records - and the dropdown to a filtered dataset.
Simply adding a deleted column was not enough - there had to be a way to see a deleted record in the text portion of a combo box while at the same time filtering out deleted records in the drop down.
In the end, I wrote a custom user control to handle this.