方法一:
可以在前台设置DropDownList的DataSource方法二:
在后台的ItemDataBound事件中绑定

解决方案 »

  1.   

    方法二的Demoprivate void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {  
    DropDownList dropTemp;
    string strState;
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    strState = ((DataRowView)e.Item.DataItem).Row["state"].ToString(); //对DropDownList做数据绑定
    dropTemp = (DropDownList)e.Item.FindControl("DropDownList1");
    if(dropTemp != null)
    {
    SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
    string strSql = "select distinct state from authors";
    SqlCommand cmd = new SqlCommand(strSql, cn);
    cn.Open();
    dropTemp.DataSource = cmd.ExecuteReader();
    dropTemp.DataTextField = "state";
    dropTemp.DataBind();
    cn.Close(); //到DropDownList中根据type的值去找需要设置为选中状态的项目,将其设置为选中
    ListItem item = dropTemp.Items.FindByText(strState);
    if(item != null)
    {
    item.Selected = true;
    }
    }
    }
    }
      

  2.   

    来自固定的列表 
    那么就再弄一个datasource 然后绑定到dropdownlist 就好饿
      

  3.   

    感谢amandag(高歌),你介绍的方法是可行的。但怎么获取每个row的DropDownList的值?
    Request["DropDownList1"].Trim().ToString()能获取吗?
      

  4.   

    Request["DropDownList1"].Trim().ToString()能获取吗?===不可以,因为 其呈现的客户端 name 不是 DropDownList1try ->foreach(DataGridItem item in DataGrid1.Items) {
           DropDownList drp = item.FindControl("DropDownList1") as DropDownList;
            if(drp != null) {
                 string val = drp.SelectedValue; 
                 // ....
           }
    }
      

  5.   

    ... ItemCommand(....
    {
          DropDownList drp = e.Item.FindControl("DropDownList1") as DropDownList;
    if(drp != null) {
    string val = drp.SelectedValue; 
    // ....
    }
    }
      

  6.   

    但怎么获取每个row的DropDownList的值?
    =================================
    客户端还是服务器端?如果是服务器端要入楼上对遍历
      

  7.   

    string strcon = "server=.;user=sa;password=sa;database=DatabaseName";
            string sql = "select DepName from DepInfo order by DepName";
            DB db = new DB(strcon);
            DataTable dt = db.GetDataTable(sql);        ListItem lst = new ListItem();
            lst.Text = "Please select";
            ddl_dep.Items.Add(lst);//dropdownlist
            for (int i = 0; i < dt.Rows.Count; i++)//fill the data into the dropdownlist
            {
                ddl_dep.Items.Add(dt.Rows[i][0].ToString());
            }
            this.ddl_dep.SelectedIndex = 0;