473,791 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting gridview row number when a template button is selected

Hi I have a gridview with one of the columns as a template column with a
button. When the user selects the button is there a way to get the row
number in the button_Click event? Another one of the columns is a template
column that has a label that I have displaying the row number.
Thanks
--
Paul G
Software engineer.
Jul 18 '08 #1
3 11465
Hi,

Assign the button a commandname...
and subscribe the rowcommand event of gridview...
void CustomersGridVi ew_RowCommand(O bject sender,
GridViewCommand EventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if(e.CommandNam e=="Add")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32 (e.CommandArgum ent);

// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = CustomersGridVi ew.Rows[index];
}

BEST OF LUCK

--------------
Munna

www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
Jul 18 '08 #2
Hi thanks for the response. I only have one button. I added the code to the
rowcommand but the event does not fire when the button is selected, perhaps
it is because my button is a template field.
--
Paul G
Software engineer.
"Munna" wrote:
Hi,

Assign the button a commandname...
and subscribe the rowcommand event of gridview...
void CustomersGridVi ew_RowCommand(O bject sender,
GridViewCommand EventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if(e.CommandNam e=="Add")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32 (e.CommandArgum ent);

// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = CustomersGridVi ew.Rows[index];
}

BEST OF LUCK

--------------
Munna

www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
Jul 18 '08 #3
On Jul 18, 1:06*pm, Paul <P...@discussio ns.microsoft.co mwrote:
Hi thanks for the response. *I only have one button. *I added the code to the
rowcommand but the event does not fire when the button is selected, perhaps
it is because my button is *a template field.
--
Paul G
Software engineer.

"Munna" wrote:
Hi,
Assign the button a commandname...
and subscribe the rowcommand event of gridview...
void CustomersGridVi ew_RowCommand(O bject sender,
GridViewCommand EventArgs e)
* {
* * // If multiple buttons are used in a GridView control, use the
* * // CommandName property to determine which button was clicked.
* * if(e.CommandNam e=="Add")
* * {
* * * // Convert the row index stored in the CommandArgument
* * * // property to an Integer.
* * * int index = Convert.ToInt32 (e.CommandArgum ent);
* * * // Retrieve the row that contains the button clicked
* * * // by the user from the Rows collection.
* * * GridViewRow row = CustomersGridVi ew.Rows[index];
}
BEST OF LUCK
--------------
Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com- Hide quoted text -

- Show quoted text -
You have to add: onRowCommand="G ridView_RowComm and" to the GridView
asp for it to recognize the RowCommand event.

regards,

Big B
Jul 18 '08 #4

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

Similar topics

3
13755
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum. Everyone wants to do a java confirmation box when a user clicks the delete button. Fair enough, basic user design rules state that you should always confirm a delete action. There is also a consensus that the best way to do this is a template...
4
13497
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. I just set the GridView.DataSource once, and call DataBind(); I'd like to drive the application from the GridView control, by including command buttons that allow editing of the data. Starting out simple, I have a DataTable with a boolean...
1
9358
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
9
3532
by: hazz | last post by:
I want to display 'n' records for a table-driven data entry page. The first column should be readonly and the 2nd column, a checkbox WRITABLE (NOT READONLY). I can't use the gridview because it creates -> checked="checked" disabled="disabled" What I need is more like this; <form id="form1" runat="server"> <div> <table>
10
6694
by: Carlos | last post by:
Hi all, I have a form with an input radio control in a template field. When the user selects an option, and press a button the selection disappears.. I would like the selection to persist after the button makes the postback, I tried using the findcontrol but it returns null, and do not know how to make sure that the radio selected persist after the button action makes the postback.
4
1980
by: svgeorge | last post by:
I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) -------------------------------------------------------------------------------- How TO COLLECT THE ROWS CHECKED IN CHECK BOX IN THE DATASELECTED TO ANOTHER GRID VIEW ON CLICLING BUTTON I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) SIMILLAR TO HOTMAIL MODEL.....CHECK THE MAILS AND BRING THE CHECKED DATA TO ANOTHER PAGE
4
11900
by: Jeff | last post by:
Hi, I have a ASP.NET 2.0 Web Application. Many of the pages use the ASP.NET GridView with paging and sorting. One of the columns of this Gridview is a template column (LinkButton). The data being retrieved and showed in this GridView produce more than one page of data. A given user clicks on the first row hyper link on the Grid on the first page, then the first row hyper link color changes to look as "visited". Then the user navigates to...
2
2833
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
6
1986
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview control with a template column that has a textbox and when the control is bound to the datasource the textbox is filled ok. I then change what is in the textbox in the gridview control and in the gridview_RowDataBound event I have string DiscDescrip = Convert.ToString((e.Row.Cells.FindControl("txbxDiscgv") as TextBox ).Text); This returns what was initially loaded in the textbox but not what I had just changed it...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10207
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...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
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
9030
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
7537
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
6776
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
5435
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...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.