?
Solved

Create Click EVent on Buttons in GridView

Posted on 2006-06-22
7
Medium Priority
?
930 Views
Last Modified: 2012-08-13
Hi,

Can someone please tell me how I can apply a click event to a button in a GridView.  I add a templateControl, and add two buttons.  What I want to do is for example, when the button is clicked , the event should be a response.write

a:
The COmmand Argument of the button
b:
The value in the 1 st Cell of that Row.

I have been casting, using different Event Args and I still cannot do it. It is really annoying.

Thanks in advance

ANdrew
0
Comment
Question by:REA_ANDREW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16957902
You will need to catch the button click event in the RowCommand event.

So give your button a CommandName and then in the RowCommand event check for the CommandName and then work from there.
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16957910
Cheers Gavin, will try that now. I was hoping you would reply to this, as you are always a reliable help.

:-)

Cheers

Andrew
0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16957939
Thanks Andrew, Unfortunately I don't have a dev environment on hand to post code but it seems right from memory at least :)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16958030
ok what I have so far, is this. I have placed the button in the GridView Template Control. Then I have added the onrowcommand to the gridview tag. it calls the first function and the second function is where it handles the click. What SHould I put in or am i way of the mark?

   protected void View_C(object sender, GridViewCommandEventArgs e)
    {
        Button MyButton = new Button();
        MyButton = (Button)sender;
        MyButton.Click += new EventHandler(MyButton_Click);
    }

    void MyButton_Click(object sender, EventArgs e)
    {
        throw new Exception("The method or operation is not implemented.");
       
    }
0
 
LVL 15

Accepted Solution

by:
GavinMannion earned 2000 total points
ID: 16958204
Why are you creating a new event handler?

You can either just handle it in RowCommand or call another method to do the processing...

You say it hits the first function? If so then ignore the fact that it is a button and continue coding as usual.
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 16958238
again, you have just EDUCATED me with two small posts. Excellent. Cheers gavin.

    protected void View_C(object sender, GridViewCommandEventArgs e)
    {
        Response.Write(e.CommandArgument+""+e.CommandName);
    }

0
 
LVL 15

Expert Comment

by:GavinMannion
ID: 16958251
Glad to help, thanks for the kind words ....
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question