I inserted a label (called Label1) in a “table cell” which in its turn is inserted into a datalist.
Why is it that in this situation, I can’t use, for example, Label1.Text inside the Page_Load method, however when I insert the label outside the datalist, any reference to Label1 works perfectly?
Is there a workaround to this, as I need the label in the table cell as described and also to be able to modify its caption (.Text property) from the code-behind file, where I plan to assign it the value of a stored procedure.
Hello and thank you very much in advance.
If a control is inside a datalist, then it will be repeated for each item in the list. Consequently, it doesn’t make sense to refer to the control outside of the datalist, as ASP.NET would not know which instance to refer to – and if there is no data, there won’t even be any instances!
You can access the label given an item in the datalist, however: