从不同行表中的checkboxlist中读取多个选中的复选框 [英] read multiple checked checkbox from checkboxlist in different rows of table
问题描述
on page_Init()创建新表行和列。每一行都有标签,这将有问题,每个标签后都会有复选框列表..(类似调查,每个问题和控件都从数据库中重新发送)
r = new TableRow();
c = new TableCell();
Label dynamicLabel = new Label();
dynamicLabel.ID =lbl+ x; // x是增量
dynamicLabel.Text = questionNum +)+ questionText;
c.Controls.Add(dynamicLabel);
r .Cells.Add(c);
tbl.Rows.Add(r);
然后复选框是动态创建的
ckbx = new CheckBoxList();
ckbx.ID =c+ x; // x是增量
ckbx.Items.Add(new ListItem(optionField));
c.Controls.Add(ckbx);
r.Cells.Add(c);
tbl.Rows.Add(r);
读取已选中的复选框
for (int i = 0; i< ckbx.Items.Count; i ++)
{
if(ckbx.Items [i] .Selected)
{
xval = new Label();
xval.ID =x+ y;
xval.Text = ckbx .Items [i] .Text;
show.Controls.Add(xval);
}
}
在Default.aspx中
< form id =form1runat =server>
on page_Init() new table row and column is created. Every row will have label that will have quesion and after every label there will be checkboxlist..(its like survey where every question and controls are reterived from database)
r = new TableRow();
c = new TableCell();
Label dynamicLabel = new Label();
dynamicLabel.ID = "lbl" + x; //x is incremental
dynamicLabel.Text = questionNum+")"+questionText;
c.Controls.Add(dynamicLabel);
r.Cells.Add(c);
tbl.Rows.Add(r);
then checkboxlist is created dynamically
ckbx = new CheckBoxList();
ckbx.ID = "c"+x; //x is incremental
ckbx.Items.Add(new ListItem(optionField));
c.Controls.Add(ckbx);
r.Cells.Add(c);
tbl.Rows.Add(r);
To read checkbox that are checked
for (int i = 0; i < ckbx.Items.Count; i++)
{
if (ckbx.Items[i].Selected)
{
xval = new Label();
xval.ID = "x" + y;
xval.Text = ckbx.Items[i].Text;
show.Controls.Add(xval);
}
}
in Default.aspx
<form id="form1" runat="server">
< asp :表ID =tblrunat =server>
< asp:按钮ID =btnSetrunat =serverText =Submit onclick =btnSet_Click/>
< asp:Panel ID =showrunat =server>
<asp:Table ID="tbl" runat="server" >
<asp:Button ID="btnSet" runat="server" Text="Submit" onclick="btnSet_Click" />
<asp:Panel ID="show" runat="server">
< / form>
问题:我只能看到选中的复选框列表的最后列表...请帮助我想看到来自不同复选框组的所有选中复选框...
</form>
problem: i can see only last list of checkboxlist selected...please help i want to see all the selected checkbox from different checkbox group...
推荐答案
你能详细说明这个问题吗?
Can you more elaborate the question?
这篇关于从不同行表中的checkboxlist中读取多个选中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!