Solved

Create Click EVent on Buttons in GridView

Posted on 2006-06-22
7
926 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
Independent Software Vendors: 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 500 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

Technology Partners: 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!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 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