Just wondering which is the best asp.net control to allow a user to enter data into a table and then save it. Then the code开发者_如何学Cbehind can iterate the the rows and save each row to the database. Then load the table when the user wants to see the data. Would this be the repeater or Gridviewcontrol?
Then the codebehind can iterate the the rows and save each row to the database.
This is not good approach
User must be able to edit one row only
To edit next row user must save (or cancel) current row's data
Thus, you can avoid many problems with data synchronization
For me, DataGrid or GridView can be used when you need to display data with able to edit each row, sorting, paging etc.. If you want just to display one table, Repeater is more prefered.
But, of course, to allow user to fill all table at one time it's not good idea. You can create some form to add one row and then when user click save button, save data in db, clear form for adding second one and somewhere below display table with already added data. But i don't know what your application needs exactly. Up to you.
Hope it will be helpful. Good luck ))
Best regards, Dima.
Depends how complex your data is, how much time you have available and if it needs to be lightweight/ resource efficient. If its a simple table you want to expose for editing and it needs to be quick and efficient I would suggest that you go with writing a bespoke, editable repeater. If you're in a hurry and it just needs to work and performance/resource requirements aren't an issue then go with a Datagrid or another .Net control. They tend to be a bit heavy-weight for many scenarios and have lots of functionality which ends up unused.
Having said that, things like paging will involve you devising more complex code - if these are concerns, go with a 'ready rolled' solution ;-)
Neither, use the GridView
or the DataFormView
(sorry not sure about that last name).
The Repeater hasn't a template for Edit, and in a GridView you can edit only a row at time. I think you've to made a workaround on a bindable control (also the GridView) to obtain this behaviour.
GridView doesn't allow you to do anything like this. Repeater on its turn is more about representing data than manipulating it. You can accomplish what you want with Repeater though but you should understand that 95% of the work you have to do manually.
For example you can create a Repeater containing editable controls in each row (textboxes, dropdowns or whatever you need) and external Save button that will iterate through Repeater's rows and save all the data.
It's not as easy as it might look like, but it's possible. On the other hand you can try to find some free third-party controls via Google that already implement such UI.
精彩评论