473,236 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

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 28068
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(object sender, EventArgs e)
{
SetLinkedTable(GetSource())
}

private void SetLinkedTable(DataTable source)
{
gvLinkedTable = (GridView)skin.FindControl("gvLinkedTable");
AttachEvents();
gvLinkedTable.DataSource = source;
gvLinkedTable.DataBind();
this.Controls.Add(skin);
}

private void AttachEvents()
{
gvLinkedTable.RowCommand +=new
GridViewCommandEventHandler(gvLinkedTable_RowComma nd);
gvLinkedTable.RowDataBound += new
GridViewRowEventHandler(gvLinkedTable_RowDataBound );
}

private void gvLinkedTable_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int pk = Convert.ToInt32(e.CommandArgument);
DeleteItem(pk);
SetLinkedTable(dt);
}
}


"clickon" <cl*****@discussions.microsoft.comwrote in message
news:D8**********************************@microsof t.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(object sender, EventArgs e)
{
SetLinkedTable(GetSource())
}

private void SetLinkedTable(DataTable source)
{
gvLinkedTable = (GridView)skin.FindControl("gvLinkedTable");
AttachEvents();
gvLinkedTable.DataSource = source;
gvLinkedTable.DataBind();
this.Controls.Add(skin);
}

private void AttachEvents()
{
gvLinkedTable.RowCommand +=new
GridViewCommandEventHandler(gvLinkedTable_RowComma nd);
gvLinkedTable.RowDataBound += new
GridViewRowEventHandler(gvLinkedTable_RowDataBound );
}

private void gvLinkedTable_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int pk = Convert.ToInt32(e.CommandArgument);
DeleteItem(pk);
SetLinkedTable(dt);
}
}


"clickon" <cl*****@discussions.microsoft.comwrote in message
news:D8**********************************@microsof t.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.DataBind()
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 CreateChildControls() of
another usercontrol
( the form creator usercontrol)
"clickon" <cl*****@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.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(object sender, EventArgs e)
{
SetLinkedTable(GetSource())
}

private void SetLinkedTable(DataTable source)
{
gvLinkedTable = (GridView)skin.FindControl("gvLinkedTable");
AttachEvents();
gvLinkedTable.DataSource = source;
gvLinkedTable.DataBind();
this.Controls.Add(skin);
}

private void AttachEvents()
{
gvLinkedTable.RowCommand +=new
GridViewCommandEventHandler(gvLinkedTable_RowComm and);
gvLinkedTable.RowDataBound += new
GridViewRowEventHandler(gvLinkedTable_RowDataBoun d);
}

private void gvLinkedTable_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int pk = Convert.ToInt32(e.CommandArgument);
DeleteItem(pk);
SetLinkedTable(dt);
}
}


"clickon" <cl*****@discussions.microsoft.comwrote in message
news:D8**********************************@microso ft.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*************@TK2MSFTNGP03.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.DataBind()
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
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...
1
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,...
1
by: keithb | last post by:
What causes a GridView RowCommand Event to intercept a RowDeleting Event? How to cure it? Thanks, Keith
13
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...
7
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...
2
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...
1
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,...
0
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...
8
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.