Find parent control from child control

Posted by Shoyeb under ASP.NET on 11/19/2013 | Points: 10 | Views : 1506 | Status : [Member] | Replies : 2
Hi All,

I have a gridiew inside that i have child control means (listview) in list view i am using link button .. now how can i find gridview control( lable etc) while clicking on link button.

my code for listview contrl( link button) is like this

protected void lnktestname_Click(object sender, EventArgs e)
LinkButton linkbtn = (LinkButton)sender;
ListViewItem item = (ListViewItem)(linkbtn.NamingContainer);


inside gridview there is lable and textbox now how i can found this control inside this code ..

i have used .parent.parent but nothing happening.


Posted by: vishalneeraj-24503 on: 11/19/2013 [Member] [MVP] Platinum | Points: 25

You can find GridViewRow as below:-

GridViewRow gvr = (LinkButton)sender).NamingContainer;

//now you can find control like this,
Label lbl_name = (Label)gvr.FindControl("lbl_emp_name");

Shoyeb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response