Foreach variable does not exist inside asp tag

and on the third line an error appears: Compiler error message: CS0103: the name "t" does not exist in the current context.

Can someone help me?

+4
source share
1 answer

You cannot use LinkButton inside a loop like this, lower variables like this inside a button code. And the variable that is not found is inside LinkButton.

I suggest using a repeater to create your loop or PlaceHolder and create link buttons by adding controls to the same loop in your code.

Here is an example

foreach (string s in new string[] { "ena", "dyo" }) { Literal lTitle = new Literal(); lTitle.Text = "<Br>" + s; LinkButton lbButton = new LinkButton(); lbButton.Text = "<br>" + s; phAddOnMe.Controls.Add(lTitle); phAddOnMe.Controls.Add(lbButton); } 

and on the page

 <asp:PlaceHolder runat="server" ID="phAddOnMe"></asp:PlaceHolder> 
+1
source

All Articles