you cannot declare DDL_MZ this way, since each row of DataGrid has one dropdownlistyou need to access it in some event handler for the DataGrid like thisDropDownList ddl = (DropDownList)DataGrid1.Items[DataGrid1.EditItemIndex].FindControl("DDL_MZ ");
您的意思是我不能在页面代码的模板列中声明dropdownlist是吗?
您说datagrid中每行都包含一个dropdownlist,那我如何将数据源绑定到dropdownlist中去?
谢谢
{
SqlConnection myConnection = new SqlConnection("Data Source=localhost;User ID=sa;Password=sa;Initial Catalog=rcdatabase");
SqlDataAdapter myCommand = new SqlDataAdapter(DDLSQLstring, myConnection); DataSet ds = new DataSet();
myCommand.Fill(ds, TableName);
DropDownList DDL_General;
DDL_General = (DropDownList)MyDataGrid.Items;
[MyDataGrid.EditItemIndex].FindControl("DDL_MZ ").DataSource=ds.Tables[TableName].DefaultView;
[MyDataGrid.EditItemIndex].FindControl("DDL_MZ ").DataBind();
}
这样好像不行,请思归大哥哥明示,在页面代码中还用自定义dropdownlist吗?在后置代码中如何绑定数据源?