Updating gridview data
If we use proper command names for the buttons like “EDIT”, “DELETE”, “UPDATE”, “CANCEL” these will also trigger the appropriate Grid View Events.
Ok let’s move on to Code behind what we have to do when user clicks Edit, Delete, Update and Cancel When we click on Edit the On Row Editing event will be fired.
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.
Hope this saves someone a full day of research (and possibly some hair)!
Basically, I was trying to convert an existing data-display-only Grid View (ie, no special functions) into one where I can update a field, namely the inventory for displayed products. New Edit Index 'set to selected row Bind Grid View() ' your own subroutine that you use to bind your datagrid End Sub Protected Sub Grid View1_Row Canceling Edit(By Val sender As System.
After working with Data Grids so efficiently, I was scared that Grid Views were going to be a million times more complex.
You can see the C# code below will give the row number whatever you are editing by New Edit Index property.
The source may be: a hard-coded value like "3.95", which would return all products less than .95; the value of a Web control on the page, allowing the user to enter a price bound in a Text Box; from the querystring; from session state; and so on.
We will use Template Field, whenever we want to define some custom control in the data bound controls like Grid View, Data Grid or Data Repeater.
If he clicks edit (or) in the edit mode he can be able to see the Textbox.
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.
With a little bit of research, a lot bit of patience, and some help from the internet community, I was able to solve all my issues, and pretty elegantly at that. You can’t do something like Dim name As Hyper Link Dim inv As Text Box name = CType(Grid View1. in an actual post, just email me or comment somewhere and we’ll talk about it.
May be you may think why am I using link buttons as we are provided with some command field buttons by Grid View.