在datagrid中,将某一列转化为模板列,当点更新时,改列变成一个dropdownlist,里面绑定了数据库中的某一项,怎么做啊,我在模板列的EditItemTemplate中加入了一个dropdownlist,但是不能点它编写绑定的程序,从那可以写绑定的程序??

解决方案 »

  1.   

    ItemCreated事件中
    if(e.ItemType==ListItemType.Edit)
    {
       DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList1");
       绑定ddl就可以了
    }
      

  2.   

    是这样写么??可是这样写找不到ddl啊??private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    DropDownList ddl=(DropDownList)e.Item.FindControl("DropDownList5");
    SqlConnection con=new SqlConnection("server=3GTY;database=3GTY;uid=sa;pwd=sa");
    SqlDataAdapter sda=new SqlDataAdapter();
    sda.SelectCommand=new SqlCommand ("select typeID from TypeTable",con);
    DataSet ds=new DataSet ();
    sda.Fill (ds);
    this.ddl.DataSource=ds;
    this.ddl.DataBind();
    }