Solved

Create Click EVent on Buttons in GridView

Posted on 2006-06-22
7
918 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
  • 4
  • 3
7 Comments
 
LVL 15

Expert Comment

by:GavinMannion
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Andrew, Unfortunately I don't have a dev environment on hand to post code but it seems right from memory at least :)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 20

Author Comment

by:REA_ANDREW
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Glad to help, thanks for the kind words ....
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now