Hi, I am trying to access my HyperLink1 that is in the ItemTemplate of my DataGrid. I am using VB.NET but it should be the same as C# i'm sure.
Here's what I'm trying to do:
HyperLink1.Attributes.Add("onclick", "window.open('popup.aspx',null,'height=250, width=250,status= no, resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
I have a link with ID=HyperLink1 but i get a message "HyperLink1 is not declared".
What am I doing wrong?
Loading
Basheer NassrallahPosted Oct 3, 2006, 8:18 PM
the thing is , that the controls are not strongly typed because they're not predefined, two ways to access a control inside a Datagrid/Gridview..
1) get a reference to the row then to his cells, and from the cell's controls choose the appropriate one, and parse it into the control type u want :
((HyperLink)DataGrid1.Rows[RowNumber].Cells[CellNumber].Controls[ControlNumber]).Text;
another way to do it , is to get to the row you want then just try to get the control by it's id :
((HyperLink)DataGrid1.Rows[RowNumber].FindControl("HyperLink1")).Text;
JeyakumarPosted Oct 3, 2006, 12:38 AM
+First of all, you should understand that, You can able to access all the controls which are placed directly in the FORM only.
+If a control is placed inside another control, then you should first reference the Parent Control ( in your case, it is Template Container) and from that container control, you should reference the Child Controls ( HyperLink).
I hope you got the idea. Cheers!!