GridView Method Call Trouble

L

luisxx

WinSrv2003 SP1
IIS 6.0
ASP.NET C#, 2.0
SQL 2005
All on same machine

Hello everyone!

I have a method in ASP.NET 2.0 that I can't seem to get right,
Gridview1_rowcommand.

I am using a GridView control with a data source to SQL Server 2005. I
would like it to call the Gridview1_rowcommand when a <asp:ButtonField
ButtonType="Link" ...> button in the GridView is clicked, then I do
stuff in it.

I found one way

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
GridView1.RowCommand += new
GridViewCommandEventHandler(GridView1_RowCommand);
}

This works, providing a method "GridView1_RowCommand"; however, the
repercussion is that it overrides other functionality such as the edit
link in the Gridview control. The edit link in the GridView will do
everything like the asp button link. Is there a way to separate the
call so as to not do the same processing? Or, Is there a way within
the rowCommand to tell which one item in the row was click, either the
button link or edit button?

Luis
 
G

Guest

Why are you programatically creating the RowCommand event handler. The only
reason to do this is if you are also programatically creating the GridView.
If you are creating the GridView in the markup, simply hook it up to an event
handler in the code behind page e.g.

<asp:GridView ID="gvwMyGridView" runat="server"
OnRowCommand="gvwMyGridView_RowCommand" >

Code Behind:

protected void gvwMyGridView_RowCommand(object sender,
GridViewCommandEventArgs e)
{

}
 
L

luisxx

Thanks Clickon for replying.

It worked nicely. Glad to know I was programmatically creating the
RowCommand event handler. I am still new to ASP.NET 2.0 and Csharp,
and your post really helped.

Luis :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top