Solved

Create Click EVent on Buttons in GridView

Posted on 2006-06-22
7
920 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
Not showing page correctly 3 31
Receiving a string from a WebService Push 21 37
C#  Radio button search for Date not DateTime 4 35
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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

13 Experts available now in Live!

Get 1:1 Help Now