Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建运行时链接按钮_C# - Fatal编程技术网

C# 创建运行时链接按钮

C# 创建运行时链接按钮,c#,C#,为了创建运行时链接按钮,我使用了以下代码 for (int i = 0; i <= 10; i++) { r = new TableRow(); t.Rows.Add(r); for (int j = 0; j <= 2; j++) { c = new TableCell(); r.Cells.Add(c); LinkB

为了创建运行时链接按钮,我使用了以下代码

for (int i = 0; i <= 10; i++)
        {
            r = new TableRow();
        t.Rows.Add(r);

        for (int j = 0; j <= 2; j++)
        {
            c = new TableCell();

            r.Cells.Add(c);

            LinkButton btnLnk = new LinkButton();
            btnLnk.Text = "Hello";
            btnLnk.Visible = true;
            btnLnk.CommandName = "Test";
            btnLnk.CommandArgument = "1";
            btnLnk.ID = "Hi";

            c.Controls.Add(ll);

        }

    }

for(int i=0;i确保您的表(t)在表单标记内。

确保您的表(t)在表单标记内。

最有可能的情况是,添加链接按钮的表所在的表单没有指定runat=server属性,或者该表根本不在表单中

确保你有这样的东西

<form runat="server">
 <!--table to which you are adding your rows-->
</form>

最有可能的情况是,要添加链接按钮的表所在的表单没有指定runat=server属性,或者该表根本不在表单中

确保你有这样的东西

<form runat="server">
 <!--table to which you are adding your rows-->
</form>

首先给你的表单提供id,比如说

然后在代码隐藏中,您可以像这样向表单中添加表

myForm.Controls.Add(t);

首先给表单提供id,比如说

然后在代码隐藏中,您可以像这样向表单中添加表

myForm.Controls.Add(t);