Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.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# 设置html输入代码的名称_C#_Asp.net_Html - Fatal编程技术网

C# 设置html输入代码的名称

C# 设置html输入代码的名称,c#,asp.net,html,C#,Asp.net,Html,我试图设置一个单选按钮的名称,我从后面的代码生成。我不能让它工作。有什么想法吗 我是如何做到的: protected void repProductsDatabound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {

我试图设置一个单选按钮的名称,我从后面的代码生成。我不能让它工作。有什么想法吗

我是如何做到的:

   protected void repProductsDatabound(object sender, RepeaterItemEventArgs  e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {

            Enums.ProductCode product = (Enums.ProductCode)e.Item.DataItem;
            HtmlTableRow row = new HtmlTableRow();

            HtmlTableCell buttonCell = new HtmlTableCell();
            HtmlInputButton btn = new HtmlInputButton("radio");
            btn.Name = "productsRadioGroup";
          //  btn.ServerClick += onProductSelectionChanged;
            buttonCell.Controls.Add(btn);
            row.Controls.Add(buttonCell);


            HtmlTableCell ProductCell = new HtmlTableCell();
            ProductCell.InnerText = product.ToString().Replace("_", " ");
            row.Controls.Add(ProductCell);

            e.Item.Controls.Add(row);

        }

    }
结果

<td><input name="ctl00$MainContent$repProducts$ctl01$ctl02" type="radio" /></td>
        <td>Be Business</td>
    </tr>
    <tr>
        <td><input name="ctl00$MainContent$repProducts$ctl02$ctl02" type="radio" /></td>
        <td>Be BusinessLite</td>
    </tr>
    <tr>
        <td><input name="ctl00$MainContent$repProducts$ctl03$ctl02" type="radio" /></td>
    <td>Be BusinessPro</td>
</tr>

做生意
从商
做生意专家

看起来您无法设置中继器中单选按钮的名称。这是一个已知的错误

为什么要在repeater的OnItemDataBound事件中动态地向页面添加控件?这绕过了中继器的整个功能。试试btn.Attributes.Add(“name”,“your_name”);“name”属性显然被ASP.NET的命名约定覆盖了。我不认为在将该属性添加到页面之前的任何时候设置该属性都会产生影响。汤姆·斯奎尔斯:你为什么不告诉我们你在这里想要完成什么?莫阿尔科德普兹:我想建立一个单选按钮组。它们都需要具有相同的名称,以便只能选择一个