Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Which GridView events are fired when :
1. User clicks a button in ItemTemplate.
2. User clicks a button in FooterTemplate.
3. User clicks a button in HeaderTemplate.
4. User clicks a button in EditItemTemplate.

Q. When is RowCommand Event is fired?


I probably already know the answers to the above questions, but just want to clear up some confusions and doubts. Answers to the above questions will be very helpful for me for my clear understanding.
Posted
Updated 3-Aug-13 2:07am
v2
Comments
arbaaz jalil 3-Aug-13 7:41am    
I have read OnRowEditing event occurs when a row's Edit button is clicked, but before the GridView control enters edit mode. What is meant by "Edit Button"? isnt it supposed to be just any button with any name as long as its on ItemTemplate?

1 solution

Refer -

1. GridView.RowCommand Event[^].
Quote:
Occurs when a button is clicked in a GridView control.
2. Also check How to: Respond to Button Events in a GridView Control[^].

So, the answers to 1, 2, 3, 4 also implies to RowCommand event, if you are using the Buttons(ButtonField, Button, LinkButton, or ImageButton) inside them and you have a custom Command.
 
Share this answer
 
v3
Comments
arbaaz jalil 3-Aug-13 8:46am    
Ok so RowCommand gets executed in all the 1 to 4 cases but what about OnRowEditing ? When does that get executed(assuming i am not using command field.) I read somewhere on msdn that it gets executed when Edit button is clicked , what is meant by Edit Button? If i am not using CommandField, have a GridView with few Template fields with one one ofthe column with buttons. ANdi if click that button wont OnRowEditing be fired along with RowCommand?
Yes, you can raise the RowEditing Event when you specify the CommandName as "Edit" - Refer 1st link under "Remarks" heading.

So, if you are using TemplateFields and specify one of those commands given in the link, then corresponding event will be raised.

RowCommand gets raised if you only specify your custom commands other than than those specified in the MSDN link. (I have also updated my answer and included this.)

"Edit Button" is generated when you use a CommandField like below...

<asp:CommandField ShowEditButton="True"></asp:CommandField>


Refer - Asp.net insert, Edit, update, delete data in gridview, where you can see how RowEditing event is raised using ImageButtons inside TemplateField.
arbaaz jalil 3-Aug-13 13:55pm    
So basically, i can specify as many button as i want in ItemTemplate , EditItemTemplate, footer and Header and i will just need to specify their command name and handle them in RowCommand event right? And if i set the command name to "Edit", "Update","Cancel" or "Delete" of any button any template or footer or header of a GridView then "RowEditing", "RowUpdating and RowUpdated" , "RowCancelingEdit" events will be fired respectively. Am i on the right track?
Exactly... You are correct. Go on. :) High five.
arbaaz jalil 5-Aug-13 3:25am    
haha Hi5! Thanks Mate!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900