473,655 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView with 2 buttons. Which one was clicked

I have a grid view with several text columns and 2 button columns. How do I
tell which button on which row was clicked?
Nov 17 '06 #1
5 1919
Hi Yossi,

Set the CommandName property of the two buttons eg button1.Command Name =
"This" button2.Command Name = "That"
handle the RowCommand of the GridView and switch through the commandnames

protected void GridView1_RowCo mmand(object sender, GridViewCommand EventArgs
e)

{

switch (e.CommandName)

{

case "This":

Response.Write( "This was clicked");

break;

case "That":

Response.Write( "That was clicked");

break;

}
}
"Yossi" <jo**********@f irstfi.comwrote in message
news:Oa******** *****@TK2MSFTNG P02.phx.gbl...
>I have a grid view with several text columns and 2 button columns. How do
I tell which button on which row was clicked?

Nov 17 '06 #2
That solves half of the problem.

Now how do I determine on which row that button is located?
"Onwuka Emeka" <bu******@hotma il.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
Hi Yossi,

Set the CommandName property of the two buttons eg button1.Command Name =
"This" button2.Command Name = "That"
handle the RowCommand of the GridView and switch through the commandnames

protected void GridView1_RowCo mmand(object sender,
GridViewCommand EventArgs e)

{

switch (e.CommandName)

{

case "This":

Response.Write( "This was clicked");

break;

case "That":

Response.Write( "That was clicked");

break;

}
}
"Yossi" <jo**********@f irstfi.comwrote in message
news:Oa******** *****@TK2MSFTNG P02.phx.gbl...
>>I have a grid view with several text columns and 2 button columns. How do
I tell which button on which row was clicked?


Nov 17 '06 #3
"Yossi" <jo**********@f irstfi.comwrote in message
news:Oi******** ******@TK2MSFTN GP03.phx.gbl...
Now how do I determine on which row that button is located?
Set the CommandArgument to the row's unique key.
Nov 17 '06 #4
How do you do that?

I am talking here about the GridView component in ASP .Net 2.0. When I look
at the source for the GridView, I see two <asp:ButtonFiel d....elements.
If I add a CommandArgument attribute, I get an error. It seems that
ButtonFields do not have a CommandArgument attribute.

"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:OI******** ********@TK2MSF TNGP03.phx.gbl. ..
"Yossi" <jo**********@f irstfi.comwrote in message
news:Oi******** ******@TK2MSFTN GP03.phx.gbl...
>Now how do I determine on which row that button is located?

Set the CommandArgument to the row's unique key.

Nov 17 '06 #5
I found the answer in the MSDN:

To determine the index of the record that raises the command event, use the
CommandArgument property of the event argument that is passed to the command
event for the data-bound control. The ButtonField class automatically
populates the CommandArgument property with the appropriate index value.

Intellisense was not showing me a CommandArgument . That is why I got
confused. Now all I have to do is set different CommandNames for each
button in order to determine which one was clicked. Before, I set the
CommandName of both buttons to Select and then I was handling the
OnSelectedIndex Changed event. That was giving me the row, but not which
button fired the select.
"Mark Rae" <ma**@markNOSPA Mrae.comwrote in message
news:OI******** ********@TK2MSF TNGP03.phx.gbl. ..
"Yossi" <jo**********@f irstfi.comwrote in message
news:Oi******** ******@TK2MSFTN GP03.phx.gbl...
>Now how do I determine on which row that button is located?

Set the CommandArgument to the row's unique key.

Nov 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2618
by: charlie_M | last post by:
Is there a way to blank the screen in a FORM's onsubmit=... to blank the screen for the user?? I asked this before and got a way to blank a table by id with "document.getElementById('tabid').style.display='none';" in the onclick event and setting the encapsulating table's ID to 'tabid'. I was wondering if this or some other similar approach that could possibly be planted globally in my pages in the onsubmit validation
3
5587
by: | last post by:
Hello, I am trying to get add a product to a cart from a gridview control when a button in the gridview is clicked. I have a book on how to do this in asp.net 2.0 but it is done by specifying the "DataTextField" as the productID of the product that I want to add. This works but the button displays the productID as the text instead of "Add to Cart". What is the best way to get this to work?
1
1652
by: Andrew Nav | last post by:
I dragged a table from a datasource on to my web form and the GridView cpntrol was created. I turned on paging, and Edit and Delete buttons. I ran the app and everything worked great - not a single line of code written yet. Then I wanted to add a simple feature where the user could filter out data based on a value in a single column. I added a little code that set the FilterExpression property of the SqlDataSource, and that seemed...
6
10078
by: Terry | last post by:
Good morning! How do I determine which SELECT button was clicked in a GridView? The multiple SELECT buttons will be used for an application approval process. Thank you in advance for your support in this matter.
2
2181
by: luisxx | last post by:
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.
1
7138
by: Abhishek Tripathi | last post by:
I have a gridview which has a custom buttonfield. I have written appropriate code in the GridView1_RowCommand function. How can I find the number of row from which the event is being generated? For example, how can I know if the user clicked on the 2nd row of the gridview ? Gridview1.selectedIndex returns -1 . Kindly assist
2
2061
by: aeden.jameson | last post by:
I have a drop-down list the I want to use to control the visibility of button fields. Here's an example of one of my button fields, <asp:ButtonField Visible='<%$ Code:ddlReason.SelectedValue = Status.Review %>' CommandName="Review" Text="Review" /> The value of ddlReason.SelectedValue within the custom expression is constant even if I select another value from the dropdown. Why does this occur?
1
1023
by: shapper | last post by:
Hello, How do I get, in a GridView Deleting event the Primary Key of the GridView row clicked? I have in my GridView the following: MyGrdiView.DataKeyNames = New String() {"TagId"} Thanks,
1
870
by: ats | last post by:
Hello. I have a list of files in a gridview on a webpage so that clients can click on the file name and view/save the file. I want to add a delete button in a column next to it and have it fire an on click event. How do I do this. I have added buttons and when I look for the on click event it is not there. Double clicking the button seems to fire the grid's inde changed event. Any help would be much appreciated. TIA --
4
6926
Ewan
by: Ewan | last post by:
Hi Im using Visual Studio 2008, i have a gridview which gets data from an SQL table. I have added the Edit option which is part of gridview. The data has a primary key set. How do i redirect to another URL when the edit option is clicked. This action should also assign the primary key as a URL Parameter, causing only that specific record to show on the Edit page. I have gone through this article:...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.