Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Deleting from a gridview control [modified]

Deleting from a gridview control [modified]

Scheduled Pinned Locked Moved ASP.NET
helpdatabasecsharpcssasp-net
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Senseicads
    wrote on last edited by
    #1

    Hi I am a long time powerbuilder developer who has recently started a new job working with asp.net and vb. I am currently using a grid view to display a list of users. I need to be able to delete an unused user from the table. ie one that has had nothing in the referenced table assigned to him. I have set up the auto command button thingy to delete the user in the current row My database works ace with the constraints set up correctly. If I attempt to delete a user that has been referenced elsewhere I get a lovely asp error page saying that it fails the constraint check, and if he hasn't been referenced anywhere he gets deleted. However I want to be able to handle the error so that I get something more meaningful for the user. I have thought about two ways of doing this, and I am a bit stuck on getting either way to work. The first way I thought of was to place in the rowdeleting event of the gridview a check to say if there exists in the referenced table an instance of the userID then cancel the event using e.cancel(). This would work ace except that I can't for the life of me find the command to reference which row is clicked. Also this means another call to the database which prob isn't so great. The other way I thought of would be to catch the constraint exception coming from the database. However I can't find where to put this. I mean I assume its a try catch somewhere, but there is no event for the delete being run, its either rowdeleting or rowdeleted. So not sure of the way this should be handled, any help would be most appreciated. I realise this is prob a trivial explanation but there doesn't seem to be a lot of info about it around. Cheers Ian Caddick -- modified at 8:38 Wednesday 25th April, 2007 Ok then think I have managed to solve the problem I have used option one and found out how to return to the row number clicked. It might have seemed like a bit of a trivial option but after much faffing around with dictionary things discovered the datakey object! Why oh why is there not a lot of help around the net on this? This is what I came up with in the end... Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting Dim index = Integer.Parse(e.RowIndex) Dim dk As DataKey dk = GridView1.DataKeys.Item(index) Dim iOpID = dk.Value ' Check if the User Can be deleted if he can enable the delete button. Dim connecti

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups