473,832 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView RowCommand event not firing!!

I am using a GridView inside a UserControl which has a template column for
deleting the rows. Before databinding the gridview i am attaching the
RowCommand and RowDataBound event.

I am using the RowDataBound event to set the commandargument of the delete
button. The event is being fired and works fine.

When I press the delete button, the RowCommand event is not firing! and
neither is the RowDeleting (the button's commandName is "Delete")
Any idea why?


Aug 8 '06 #1
6 28179
The order that event handlers execute can cause this kind of problem. Why are
you setting the command argument of the delete button in the RowDataBound
event, why not just declare it in the markup? Try that and see if the
RowCommand event fires.

"Kevin Attard" wrote:
I am using a GridView inside a UserControl which has a template column for
deleting the rows. Before databinding the gridview i am attaching the
RowCommand and RowDataBound event.

I am using the RowDataBound event to set the commandargument of the delete
button. The event is being fired and works fine.

When I press the delete button, the RowCommand event is not firing! and
neither is the RowDeleting (the button's commandName is "Delete")
Any idea why?


Aug 8 '06 #2
I've tried it but it still wont fire the event.
Here is the code:

protected void Page_Load(objec t sender, EventArgs e)
{
SetLinkedTable( GetSource())
}

private void SetLinkedTable( DataTable source)
{
gvLinkedTable = (GridView)skin. FindControl("gv LinkedTable");
AttachEvents();
gvLinkedTable.D ataSource = source;
gvLinkedTable.D ataBind();
this.Controls.A dd(skin);
}

private void AttachEvents()
{
gvLinkedTable.R owCommand +=new
GridViewCommand EventHandler(gv LinkedTable_Row Command);
gvLinkedTable.R owDataBound += new
GridViewRowEven tHandler(gvLink edTable_RowData Bound);
}

private void gvLinkedTable_R owCommand(objec t sender,
GridViewCommand EventArgs e)
{
if (e.CommandName == "Delete")
{
int pk = Convert.ToInt32 (e.CommandArgum ent);
DeleteItem(pk);
SetLinkedTable( dt);
}
}


"clickon" <cl*****@discus sions.microsoft .comwrote in message
news:D8******** *************** ***********@mic rosoft.com...
The order that event handlers execute can cause this kind of problem. Why
are
you setting the command argument of the delete button in the RowDataBound
event, why not just declare it in the markup? Try that and see if the
RowCommand event fires.

"Kevin Attard" wrote:
>I am using a GridView inside a UserControl which has a template column
for
deleting the rows. Before databinding the gridview i am attaching the
RowCommand and RowDataBound event.

I am using the RowDataBound event to set the commandargument of the
delete
button. The event is being fired and works fine.

When I press the delete button, the RowCommand event is not firing! and
neither is the RowDeleting (the button's commandName is "Delete")
Any idea why?

Aug 8 '06 #3
Again i think you are coming up against an order events fire type problem,
you are hooking up your GridView event handlers programatically in the
PageLoad event, how do you know that the PageLoad event fires before the
RowCommand event, if the RowCommand event fires before the PageLoad event
then the event has already happened before you even wire up the event handler.

Again i can't see any good reason for hooking up your event handlers
programatically from your code, the reason you do that usually is if the
control to which you are hooking up the event handlers has also been created
programatically . If you are creating the GridView declaritively in the mark
up then also wire up your event handlers like this.

"Kevin Attard" wrote:
I've tried it but it still wont fire the event.
Here is the code:

protected void Page_Load(objec t sender, EventArgs e)
{
SetLinkedTable( GetSource())
}

private void SetLinkedTable( DataTable source)
{
gvLinkedTable = (GridView)skin. FindControl("gv LinkedTable");
AttachEvents();
gvLinkedTable.D ataSource = source;
gvLinkedTable.D ataBind();
this.Controls.A dd(skin);
}

private void AttachEvents()
{
gvLinkedTable.R owCommand +=new
GridViewCommand EventHandler(gv LinkedTable_Row Command);
gvLinkedTable.R owDataBound += new
GridViewRowEven tHandler(gvLink edTable_RowData Bound);
}

private void gvLinkedTable_R owCommand(objec t sender,
GridViewCommand EventArgs e)
{
if (e.CommandName == "Delete")
{
int pk = Convert.ToInt32 (e.CommandArgum ent);
DeleteItem(pk);
SetLinkedTable( dt);
}
}


"clickon" <cl*****@discus sions.microsoft .comwrote in message
news:D8******** *************** ***********@mic rosoft.com...
The order that event handlers execute can cause this kind of problem. Why
are
you setting the command argument of the delete button in the RowDataBound
event, why not just declare it in the markup? Try that and see if the
RowCommand event fires.

"Kevin Attard" wrote:
I am using a GridView inside a UserControl which has a template column
for
deleting the rows. Before databinding the gridview i am attaching the
RowCommand and RowDataBound event.

I am using the RowDataBound event to set the commandargument of the
delete
button. The event is being fired and works fine.

When I press the delete button, the RowCommand event is not firing! and
neither is the RowDeleting (the button's commandName is "Delete")
Any idea why?


Aug 8 '06 #4
Kevin Attard wrote:
I am using a GridView inside a UserControl which has a template
column for deleting the rows. Before databinding the gridview i am
attaching the RowCommand and RowDataBound event.

I am using the RowDataBound event to set the commandargument of the
delete button. The event is being fired and works fine.

When I press the delete button, the RowCommand event is not firing!
and neither is the RowDeleting (the button's commandName is "Delete")
Any idea why?
Do not databind on postback.
Use a construct like:
If(Not Page.IsPostback ) Then
GridView1.DataB ind()
End If

If you databind again on postback, the event handling of child buttons is
broken.

--

Riki
Aug 8 '06 #5
The reason of wiring the events at runtime is because I am creating a
dynamic form from the database. Controls are created depending on the data
of the database.

Sorry, the code should have been like this: I'm using the constructor not
the pageload event

public myUserControl()
{
SetLinkedTable( GetSource())
}

This constructor is called in the overidden method CreateChildCont rols() of
another usercontrol
( the form creator usercontrol)
"clickon" <cl*****@discus sions.microsoft .comwrote in message
news:85******** *************** ***********@mic rosoft.com...
Again i think you are coming up against an order events fire type problem,
you are hooking up your GridView event handlers programatically in the
PageLoad event, how do you know that the PageLoad event fires before the
RowCommand event, if the RowCommand event fires before the PageLoad event
then the event has already happened before you even wire up the event
handler.

Again i can't see any good reason for hooking up your event handlers
programatically from your code, the reason you do that usually is if the
control to which you are hooking up the event handlers has also been
created
programatically . If you are creating the GridView declaritively in the
mark
up then also wire up your event handlers like this.

"Kevin Attard" wrote:
>I've tried it but it still wont fire the event.
Here is the code:

protected void Page_Load(objec t sender, EventArgs e)
{
SetLinkedTable( GetSource())
}

private void SetLinkedTable( DataTable source)
{
gvLinkedTable = (GridView)skin. FindControl("gv LinkedTable");
AttachEvents();
gvLinkedTable.D ataSource = source;
gvLinkedTable.D ataBind();
this.Controls.A dd(skin);
}

private void AttachEvents()
{
gvLinkedTable.R owCommand +=new
GridViewComman dEventHandler(g vLinkedTable_Ro wCommand);
gvLinkedTable.R owDataBound += new
GridViewRowEve ntHandler(gvLin kedTable_RowDat aBound);
}

private void gvLinkedTable_R owCommand(objec t sender,
GridViewComman dEventArgs e)
{
if (e.CommandName == "Delete")
{
int pk = Convert.ToInt32 (e.CommandArgum ent);
DeleteItem(pk);
SetLinkedTable( dt);
}
}


"clickon" <cl*****@discus sions.microsoft .comwrote in message
news:D8******* *************** ************@mi crosoft.com...
The order that event handlers execute can cause this kind of problem.
Why
are
you setting the command argument of the delete button in the
RowDataBound
event, why not just declare it in the markup? Try that and see if the
RowCommand event fires.

"Kevin Attard" wrote:

I am using a GridView inside a UserControl which has a template column
for
deleting the rows. Before databinding the gridview i am attaching the
RowCommand and RowDataBound event.

I am using the RowDataBound event to set the commandargument of the
delete
button. The event is being fired and works fine.

When I press the delete button, the RowCommand event is not firing!
and
neither is the RowDeleting (the button's commandName is "Delete")
Any idea why?



Aug 8 '06 #6
I've eliminated the databinding on each postback as you suggested. When the
delete button is pressed, the RowCommand does not fire and when the page
loads, the gridview displays empty rows! So if I don't bind with every
postback, the data is lost. When Ive tried to press the button the second
time, the event is fired! Why is the event not firing on the first load but
only on the second?

"Riki" <ri**@dontnagme .comwrote in message
news:ub******** *****@TK2MSFTNG P03.phx.gbl...
Kevin Attard wrote:
>I am using a GridView inside a UserControl which has a template
column for deleting the rows. Before databinding the gridview i am
attaching the RowCommand and RowDataBound event.

I am using the RowDataBound event to set the commandargument of the
delete button. The event is being fired and works fine.

When I press the delete button, the RowCommand event is not firing!
and neither is the RowDeleting (the button's commandName is "Delete")
Any idea why?

Do not databind on postback.
Use a construct like:
If(Not Page.IsPostback ) Then
GridView1.DataB ind()
End If

If you databind again on postback, the event handling of child buttons is
broken.

--

Riki

Aug 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
10286
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when appropriate based on your method names . the GridView has OnRowCommand="GridView1_RowCommand" in the aspx. my problem is that the RowCommand event is firing twice (95% of the time) on the page. the other 5% it only fires once. there's no
1
2320
by: Mike P | last post by:
I have a ButtonField in my GridView with a CommandName, and I have a method which I am using to capture each click of the button : protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "OpportunityDetails")
1
2475
by: keithb | last post by:
What causes a GridView RowCommand Event to intercept a RowDeleting Event? How to cure it? Thanks, Keith
13
42076
by: AG | last post by:
I have a gridview that I bind to a List(of Type) at runtime. Not using a datasource control. The gridview has a template column with an imagebutton whose commandname is set to 'Delete'. The footer template has an commandbutton with the commandname set to 'Insert'. Both buttons cause postback, however the RowCommand event does not fire. How can I get the rowcommand to fire?
7
17327
by: =?Utf-8?B?cGF0cmlja2RyZA==?= | last post by:
Hi all! I have a gridview inside a datagrid (nested) for which (gridview) the rowcommand is not raised in order to delete a row from the grid! I also tried OnRowCommand="method", didn't work either! Does anyone know how can I make this work? Thanks in advance!
2
11042
by: John007 | last post by:
I am using a GridView in ASP.Net 2.0 to Insert, Edit, Update and Delete. I am using ItemTemplate and EditItemTemplate and the buttons are LinkButtons. I am inserting a new row from the footer. The RowCommand event is firing twice when I hit the Edit, Update, Delete and Insert buttons. The AutoEventWireup is set to false. What am I missing? Thanks.
1
2868
by: Just Me | last post by:
I have discovered a( nd its probably not news to most of you ) that if you add a button column and use the Image Button type that this event fires twice. I know its been reported about a year ago, but I cant seem to find a solution to it in terms of a fix, or explaination as to why. Any ideas here ?
0
1890
by: progman417 | last post by:
Hello, I've got a Web User Control containing a gridview with a "select record" button on each row. When the user clicks the button I want to call an event handler in the main page. My problem is that the event handler hasn't been set when I check it in the GridView RowCommand event, i.e. if (btnSelectRecordHandler != null) ...
8
7964
by: Ananthu | last post by:
Hi, I have a gridview in my web page. I have boundcolumn,checkboxcolumn and a linkbutton column. The commandName of the linkbutton column is "Select" The name of the template checkbox is "chkSwapSelect". I want to check the checkbox of the linkbutton clicked row.
0
10781
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10541
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3972
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.