Inline Editing Asp Net Gridview Rowcommand
I am using a gridview in aspx and i have two pages that registration and details.aspx once registration completed it should goto details page in details.aspx i have kept a gridview in that GV i am supposed be use row command event for a button it should show the all the rsults for the students with the edit button as the last column for all the students i used item template for that. but in row command event i dont know the function to write if user clicking edit it should goto the edit page using the userid the id should be noon editable mode and other fields can editable.
details.aspx
details.aspx.cs
}
Samaritan_LearnerSamaritan_Learner2 Answers
First your button control CommandArgument
property must have a unique value in each row:
Then on your code behind GridView3_RowCommand
event you will have something like the code below:
Two methods To do this Windows 7 ems enabled.
Asp Gridview Rowcommand
Method 1
Please change these things in markup
- Change
CommandName='EditUserName'
- Omit the
CommandArgument
. We don't need this
Code-behind
Method 2
Give a CommandArgument
. You can give many different arguments like these
CommandArgument='<%# Container.DataItemIndex %>'
CommandArgument='<%# Container.DisplayIndex %>'
CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'
(the one Ali gave)
Now in code, do this
P.S:
1.The reason for changing the CommandName is that if the CommandName='Edit'
, it will fire the RowEditing
event which will give you this error
The GridView 'GridView3' fired event RowEditing which wasn't handled.
2.Place the Page_Load code inside if(!IsPostBack)
or else none the above methods work.