In my gridview I have a textbox and a save icon which allows a user to enter a date and click save which saves the date to the database for that record pointed to in the row. The problem I have is that I don’t know how to get the row to process the save in the codebehind. Normally I would set the command-argument equal to the product ID and then in the codebehind handle the event where the commandname matches the commandname for the save icon. I have the problem then though of not knowing which row caused the event.
If I use a buttonfield, I know it sets the commandargument to the row index, but the problem I have then is having no way of getting the product_id.
I need the row index in order to use gridview.rows[index].findcontrol() to be able to get the date out of the text box that the user is typing the date into.
Can anyone solve this conundrum and suggest the best way to overcome this issue?
If ProductID is a primary key, you can use the DataKeyNames property of the GridView.
Then, you can get the ProductID of the nth row with the expression:
Hello, use the gridView _RowUpdating event:
protected void gridView1_RowUpdating(object ender, GridViewUpdateEventArgs e)
// Code to save the values.
// You can modify them here again if you have any business logic
Also in the aspx use <%# Bind("DateValue") %> instead of EVal
and for your save button have the : CommandName="Update"
Hope this would help and solve your problem.
Please click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.