Add New Row to GridView without DataBind

前端 未结 2 1834
鱼传尺愫
鱼传尺愫 2021-01-05 18:47

I have a GridView that allows editing the values in every column, in every row, all the time. The user enters in all their changes, clicks Save once and all changes are com

相关标签:
2条回答
  • 2021-01-05 19:06

    You could dynamically add the new row via javascript, and on the save command look for newly added rows. That is fairly common.

    0 讨论(0)
  • 2021-01-05 19:10

    Just off my head I can think of two options. The first is to cache the original results that you are binding into the grid and when you need to add another row you add a datarow to the datatabale that you are binding to and then bind this to the grid. If there are changes in the grid then you need to update the datatable. Once all changes have been made and the user clicks the save button you can iterate through the table and update the DB with the data.

    It might look like this

    Page Loads

    • Get DB Data and put into a table
    • Bind the table to the grid
    • Store the table in a cache

    When user asks for a new row

    • Get the cached data object.
    • Update any rows that have changed
    • Add an empty row Bind to the grid

    When the user saves the grid

    • Get the cached object.
    • Make last set of updates
    • Loop through the row and update the DB

    The other way to do this is by creating the grid dynamically but this will involve far more effort than it's worth given what you have described.

    0 讨论(0)
提交回复
热议问题