我有一个 gridview ,包含3列和多行。第一列包含名称,第二列包含一个下拉列表,其中包含两个项目“是”和“否”。因此,当我想将行设置为“是”时,第3列应填充文本框,仅适用于我们选择“是”的行。
foreach (GridViewRow r in GridViewP.Rows)
{
DropDownList ddlSelection = new DropDownList();
ddlSelection.Items.Add(new ListItem("Yes"));
ddlSelection.Items.Add(new ListItem("No"));
ddlSelection.TextChanged += new EventHandler(this.ddlSelection_SelectedIndexChanged);
ddlSelection.AutoPostBack = true;
r.Cells[1].Controls.Add(ddlSelection);
}
protected void ddlSelection_SelectedIndexChanged(Object sender, EventArgs e)
{
DropDownList changed = (DropDownList)sender;
if (changed.SelectedIndex == 0)
{
foreach (GridViewRow r in GridViewP.Rows)
{
TextBox txtbox = new TextBox();
r.Cells[2].Controls.Add(txtbox);
}
}
}
如何在selecteditem
=“是”的文本框中填充第3列?它现在的工作方式是,当我将下拉列表设置为“是”时,文本框会显示每行。