Find parent control from child control

Posted by Shoyeb under ASP.NET on 11/19/2013 | Points: 10 | Views : 4912 | 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.




Responses

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

Up
0
Down
Hi,
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