选择“动态”表中的下拉列表项
//Code BehindFile
public void Button1_Click(object sender, EventArgs e)
{
while (reader.Read())
{
DropDownList ddl = new DropDownList();
string[] s = { "Present", "Absent1", "Absent2", "Absent3" };
for (int i = 0; i < 3; i++)
{
ddl.Items.Add(s[i]);
}
ddl.ID = "ddl";
TableCell c2 = new TableCell();
c2.Controls.Add(ddl);
r.Cells.Add(c2);
Table1.Rows.Add(r);
}
}
public void Button2_Click1(object sender, EventArgs e)
{
foreach (TableRow tr in Table1.Controls)
{
foreach (TableCell tc in tr.Controls)
{
if (tc.Controls[2] is DropDownList)
{
Response.Write(((DropDownList)tc.Controls[2]).SelectedItem.Text+" ");
}
}
Response.Write("<br/>");
}
问题出在下拉列表项的选择上。我无法打印相应的选定项值。有人可以帮忙吗?
//Code BehindFile
public void Button1_Click(object sender, EventArgs e)
{
while (reader.Read())
{
DropDownList ddl = new DropDownList();
string[] s = { "Present", "Absent1", "Absent2", "Absent3" };
for (int i = 0; i < 3; i++)
{
ddl.Items.Add(s[i]);
}
ddl.ID = "ddl";
TableCell c2 = new TableCell();
c2.Controls.Add(ddl);
r.Cells.Add(c2);
Table1.Rows.Add(r);
}
}
public void Button2_Click1(object sender, EventArgs e)
{
foreach (TableRow tr in Table1.Controls)
{
foreach (TableCell tc in tr.Controls)
{
if (tc.Controls[2] is DropDownList)
{
Response.Write(((DropDownList)tc.Controls[2]).SelectedItem.Text+" ");
}
}
Response.Write("<br/>");
}
Problem is with the Selection of dropdownlist items.I could not print the corresponding selected item values.could anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您位于最后一个嵌套的 foreach 中时,请检查 tc.Controls[2]。您的下拉列表是否有可能不是第三个控件?
我看不出有任何理由迫使它成为该单元中的第三个控件。
你可能会更好地做这样的事情:
而不是:
Check tc.Controls[2] when you are in the last nested foreach. Is it possible that your dropdown list is something other than the third control?
I don't see any reason that would force it to be the third control in that Cell.
You would probably be better off doing something like this:
instead of: