473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 11449
Hi,

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

// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = CustomersGridView.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 CustomersGridView_RowCommand(Object sender,
GridViewCommandEventArgs e)
{
// If multiple buttons are used in a GridView control, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="Add")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);

// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = CustomersGridView.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...@discussions.microsoft.comwrote:
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 CustomersGridView_RowCommand(Object sender,
GridViewCommandEventArgs e)
* {
* * // If multiple buttons are used in a GridView control, use the
* * // CommandName property to determine which button was clicked.
* * if(e.CommandName=="Add")
* * {
* * * // Convert the row index stored in the CommandArgument
* * * // property to an Integer.
* * * int index = Convert.ToInt32(e.CommandArgument);
* * * // Retrieve the row that contains the button clicked
* * * // by the user from the Rows collection.
* * * GridViewRow row = CustomersGridView.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="GridView_RowCommand" 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
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....
4
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. ...
1
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...
9
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...
10
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...
4
by: svgeorge | last post by:
I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) -------------------------------------------------------------------------------- How TO COLLECT THE ROWS...
4
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...
2
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...
6
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.