string strwhere = " and FID=0 and levels=1 and isshow=0 and channelid=1 and chnname='资讯'";
TypesCollection typelist = TypesDBManager.GetList(strwhere,0,0,out rowcount);
if (typelist != null)
{
TypesEntity te = new TypesEntity();
te.names = "请选择类别";
te.TypesID = 0;
typelist.Insert(0, te);
}
DropDownList1.DataTextField = "names";
DropDownList1.DataValueField = "TypesID";
DropDownList1.DataSource = typelist;
DropDownList1.DataBind();
//ListItem li = new ListItem("请选择类别", "0");
//DropDownList1.Items.Insert(-1, li);
// DropDownList1.Items.FindByValue("0").Selected = true;
//li.Text = "请选择类别";
//li.Value = "1";
//li.Selected = true;
//DropDownList1.Items.Add(li);
//DropDownList1.SelectedValue = "0";
//以上绿色部分 添加默认选项是不行的
原因:首先因DropDownList控件进行绑定时。。其索引为[0]该项已存在,
再在控件中DropDownList1.Items.Add(li); li中的索引0会导致冲突。