Update SQL db with button

Results 1 to 3 of 3

Thread: Update SQL db with button

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    Default Update SQL db with button

    This one should be easy for the .NET mavens.

    I have an ASP.NET web page tied to a SQL database. One of the fields in the SQL database is a bit field called "Marked" and determines whether or not a database item is marked for deletion.

    I've got two Gridviews on the page. The top is a list of all the items in the database that aren't Marked for deletion, and the bottom gridview is a list of items that have been marked for deletion.

    I want the user to be able to click a Delete button next to an item in the top list and "send" that item to the bottom list, where an Undo button could send it back to the top list. The idea is just to make any deleted item visible to (and restorable by) the user until the user clicks a button that deletes all marked items.

    So I want the Delete button to change the item's Marked attribute from False to True, and the Undo button to change it back from True to False.

    I assume the way to do this is to make the Delete button a Template field, then edit the VB code so a click of the button issues a command to update the item's Marked field in the database. But...I don't really know how to do that!

    What code should the Delete button's onclick sub contain to accomplish this? Can anyone give me an example or point me to some examples?

    I'm not married to doing it this way, of course, if there's a better/easier way to do it.

    Thanks in advance for any help!

  2. #2
    Join Date
    Apr 2012
    Posts
    2

    Default

    Okay, I was making it more complicated than it had to be. I realized I didn't have to do the Update programmatically; I could configure it in the SqlDataSource for the top gridview.

    But now I have another problem:

    When I click the Delete button now, its "Marked" field is changed to "True" in the database, as it should be. And the deleted item disappears from the top Gridview, as it should, since the top Gridview's data source is configured to return only items whose "Marked" field is "False." But it's not appearing in the second Gridview, which is configured to show all items whose "Marked" field is "True."

    It appears the second gridview is not refreshing when I click the "Delete" button in the top gridview. Is this because the two gridviews use separate data sources? How can I get the second gridview to update with the top one?

    Thanks.

  3. #3
    Join Date
    Dec 1969
    Posts
    95,972

    Default

    Can't possible guess without seeing code.

    But the separate data sources shouldn't matter. If the page is refreshing, the query should refresh, and it should pick up the altered records.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


More ASP Resources

Resources:
-- ASP Articles
-- ASP.NET Information
-- 4Guys ASP F.A.Q.
-- ASPFAQs.com
-- ASP Coding Tips
-- Related Web Technologies
-- User Tips!!
-- JavaScripts


Development Centers
-- HTML5 Development Center
-- Windows Mobile Development Center
-- Android Development Center
-- Cloud Development Project Center


Development Technology
Check out these sites for more articles, tutorials, FAQs, discussions, and code!
-- CodeGuru.com
-- VBForums.com
-- DevX.com
-- Developer.com
-- HTMLGoodies