2011-06-17 27 views
0

我試圖設置我從代碼後面生成的單選按鈕的名稱。我無法得到它的工作。有任何想法嗎?設置html輸入代碼的名稱後面

我怎麼做的:

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> 
+0

爲什麼在一箇中繼器的OnItemDataBound事件中動態地向頁面添加控件?這是繞過中繼器的全部功能。 – MoarCodePlz

+0

嘗試btn.Attributes.Add(「name」,「your_name」); –

+0

「name」屬性顯然被ASP.NET的命名約定所覆蓋。我不認爲在添加到頁面之前的任何時刻設置此屬性都會產生影響。湯姆斯科雷斯你爲什麼不告訴我們你在這裏試圖完成什麼? – MoarCodePlz

回答

相關問題