Click here to Skip to main content
15,888,037 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi All,

i worked to get row index.. i got link . But i want to know what process is going on....

GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;

I wanna explanation for this line...

what and the casting is going on. wat purpose i need?
Posted
Updated 29-Nov-12 2:59am
v2

1 solution

Hi,

In row command if you want to get the current row or its index, It is not directly possible. There is two way, one is on row created event on the link button(suppose, it is used for row command) save row index in link button command argument attribute.

And get the argument from row command event using e.CommandArgument

But if you want to send another value as a command argument then it creates problem. To solve this just use this code

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

Here link button (or any source) that cause to enter in row command event. Now you have selected row so you don’t need any index and directly access any row variable as sample code is given below
Label lblProdId = (Label)row.FindControl(“lblproductId”);

So whole code is just two line. Below I write whole code

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);

Label lblProdId = (Label)row.FindControl(“lblproductId”);

Thanks
Vishwa
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900