我在ASPX 拉了一个table 把cell 的ID 设成 tcell1,
然后我建了一个dropDownList 的类private DropDownList CallDrop(DataTable dt, string  text, string value)
{
DropDownList dropDownList = new DropDownList();
//dropDownList.AutoPostBack = true;
dropDownList.Style.Add("width", "150px");
ListItem item = new ListItem();
item.Text = "";
item.Value = "0";
dropDownList.Items.Add(item);
foreach (DataRow row in dt.Rows)
{
ListItem ditem = new ListItem();
ditem.Text = row[text].ToString();
ditem.Value = row[value].ToString();
dropDownList.Items.Add(ditem);
}
return dropDownList;
}
之后把DropDownList 装入cellsql = "Select * FROM DBO_AA";
dt = db.GetDataTable(sql);
tcell1.Controls.Add(this.CallDrop(dt, "area", "code"));请问我怎么去获取DropDownList 的值??

解决方案 »

  1.   

    唉``做了一个钟``终于自己解决了`private DropDownList CallDrop(DataTable dt, string  text, string value)
    {
    DropDownList dropDownList = new DropDownList();
    dropDownList.ID = text;
    //dropDownList.AutoPostBack = true;
    dropDownList.Style.Add("width", "150px");
    ListItem item = new ListItem();
    item.Text = "";
    item.Value = "0";
    dropDownList.Items.Add(item);
    foreach (DataRow row in dt.Rows)
    {
    ListItem ditem = new ListItem();
    ditem.Text = row[text].ToString();
    ditem.Value = row[value].ToString();
    dropDownList.Items.Add(ditem);
    }
    return dropDownList;
    }取值((DropDownList)this.FindControl(text)).Text //text为上面 text的取值结帖