Retrieving dropdownlist gridview rowupdating event
After working with Data Grids so efficiently, I was scared that Grid Views were going to be a million times more complex. I suppose my eyes got big when I saw all the new properties and methods, and wanted to try them all out. Most articles I found were for hardcoded datasources (especially on MSDN, ugh) and didn’t really help me much, so this post will be referring to Grid Views with dynamically bound datasources. First, create a Grid View with three bound columns and an Update/Edit/Cancel (Command Field) column: Nothing in there should be shocking to anyone: all your events are handled, you have a Hyper Link Field that uses the Data Navigate URLFields property to insert a Product ID, and you have set your Data Key Names property to your hidden field which holds your Product ID.
Edit Index = -1 'set to no selection Bind Grid View() End Sub One issue I ran into while attempting to figure this all out was if I didn’t rebind my Grid View at the end of each event, I was required to click twice to get it to select the correct row, and if I clicked around, it would always be a row behind. This blog is for nothing else than to try and help me help you and help you help me and us help everyone else try to fix anything and everything we can’t figure out with this language.
Today was spent mostly tackling the Grid View’s Update/Edit functionality, and I got incredibly frustrated, at first. So be sure to rebind your Grid View at the end of your event handler. I’ve got a pretty good handle on it as I’ve been doing it for several years, and can help with a lot, but I definitely don’t claim to know everything.
This was my first foray into this part of the Grid View’s functionality, since I haven’t really had to develop anything using it since the switch to 2.0, as everything in Data Grids still functioned fine. The Row Updating event is where it gets tricky, since pulling values is not necessarily intuitive. That’s where you come in 🙂 If you’re interested in joining the discussion to post your own problems, fixes, etc.
Hello Shivesh, You can achieve this by attaching 'onselectedindexchanged' event to Drop Down List.
In that event handler access the Grid Data Item using Naming Container property of Drop Down List.