发表于:2008-08-27 15:08:50 楼主
public class ColumnTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
DropDownList dbl=new DropDownList();
dbl.ID="dblpro_storage";
dbl.DataBinding+=new System.EventHandler(this.BindtbColumn);
container.Controls.Add(dbl);
}
public void BindtbColumn(object sender, EventArgs e)
{
DropDownList dbl= (DropDownList) sender;
DataGridItem container = (DataGridItem) dbl.NamingContainer;
string pp=((DataRowView)container.DataItem)["id"].ToString();
dbl.DataTextField ="storage_name";
dbl.DataValueField ="storage_ID";
dbl.DataSource =getstoragelist();
dbl.Items.Insert(0,new ListItem("请选择仓库","0")); //这儿不起作用
dbl.SelectedValue =((DataRowView)container.DataItem)["pro_storage"].ToString();//这儿会出错 }
}
dbl.DataBinding();
dbl.Items.Insert(0,new ListItem("请选择仓库","0"));
dbl.Items.Insert(0,new ListItem("请选择仓库","0")); //这儿不起作用
dbl.SelectedValue =((DataRowView)container.DataItem)["pro_storage"].ToString();//这儿会出错
protected void DropDownList1_DataBound(object sender, EventArgs e)
{
this.DropDownList1.Items.Add(new ListItem("请选择", "0"));
this.DropDownList1.SelectedIndex = DropDownList1.Items.Count - 1;
}
dbl.DataBound+=new EventHandler(DropDownList1_DataBound);
this.dbl.Items[this.dbl.Items.Count - 1].Value = "";
this.dbl.SelectedIndex = this.dbl.Items.Count - 1;