ASP.net创建动态单选按钮列表 [英] ASP.net creating dynamic Radio Button List
问题描述
我要创建动态单选按钮,在我的table.I有一个表Default.aspx中(ID =表1),但在我的.cs不访问表1的,这是弗里斯特问题。如果我能达到的话,我想创建动态单选按钮列表。比如我想创建一个有5个成员8单选按钮列表。我想,我这样做是用foreach块。我觉得这是code样本:
的foreach(?)
{
单选按钮单选按钮=新的单选按钮();
radioButton.Text = answer.Text;
的RadioButton.groupName = question.Id.ToString();
radioButton.ID = question.Id +_+ answer.Id; 的TableRow answerRow =新的TableRow();
TableCell的answerCell =新的TableCell();
TableCell的emptyCell =新的TableCell(); emptyCell.ColumnSpan = 2; answerCell.Controls.Add(单选)
answerRow.Cells.Add(emptyCell);
answerRow.Cells.Add(answerCell); table.Rows.Add(answerRow);
}
但我不知道回答actuallu.thanks ...
我要创建动态单选按钮,在我的table.I表中有
Default.aspx的(ID =表1),但在我的.cs不访问TABLE1这是
弗里斯特问题。
块引用>使用RUNAT =断绝属性表:
<表ID =表1=服务器> < /表>
从code,可以动态添加行和单元格。例如:
为(INT J = 0; J< 5; J ++)
{
HtmlTableRow行=新HtmlTableRow();
的for(int i = 0;我3;;我++)
{
HtmlTableCell电池=新HtmlTableCell();
单选按钮单选按钮=新的单选按钮();
radioButton.Text =TEXT+ i.ToString();
cell.Controls.Add(单选)
row.Cells.Add(细胞);
}
table1.Rows.Add(行);
}I need to create dynamic radio button in my table.I have a table in default.aspx(id =table1) but in .cs I dont access to table1 this is frist problem. if I can reach it, I want to create dynamic radio button List . For example I want to create 8 radio button list which have 5 members. I think I do this with foreach block. I find this code samples :
foreach (?) { RadioButton radioButton = new RadioButton(); radioButton.Text = answer.Text; radioButton.GroupName = question.Id.ToString(); radioButton.ID = question.Id + "_" + answer.Id; TableRow answerRow = new TableRow(); TableCell answerCell = new TableCell(); TableCell emptyCell = new TableCell(); emptyCell.ColumnSpan = 2; answerCell.Controls.Add(radioButton); answerRow.Cells.Add(emptyCell); answerRow.Cells.Add(answerCell); table.Rows.Add(answerRow); }
but I dont know actuallu.thanks for answering...
解决方案I need to create dynamic radio button in my table.I have a table in default.aspx(id =table1) but in .cs I dont access to table1 this is frist problem.
use runat="sever" attribute to table:
<table id="table1" runat="server""> </table>
From code, you can add rows and cells dynamically. For example:
for (int j = 0; j < 5; j++) { HtmlTableRow row = new HtmlTableRow(); for (int i = 0; i < 3; i++) { HtmlTableCell cell = new HtmlTableCell(); RadioButton radioButton = new RadioButton(); radioButton.Text = "Text " + i.ToString(); cell.Controls.Add(radioButton); row.Cells.Add(cell); } table1.Rows.Add(row); }
这篇关于ASP.net创建动态单选按钮列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!