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>
source share