开发者

foreach variable inside asp tag doesn't exist

and in t开发者_高级运维hird line it's get error: Compiler Error Message: CS0103: The name 't' does not exist in the current context.

can somebody help me?


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

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

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 page

<asp:PlaceHolder runat="server" ID="phAddOnMe"></asp:PlaceHolder>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜