日期:2014-05-20 浏览次数:20966 次
另一个方法中这样声明的
DropDownList ddl = new DropDownList();
ddl.ID = "ddl_" + pro.Property_ID.ToString();
ddl.DataTextField = "PV_Value";
ddl.DataValueField = "PropertyValues_ID";
ddl.Width = Unit.Pixel(400);
首次加载各DropDownList均没问题,联动效果的时候,重新绑定却出问题
[color=#FF0000]”DropDownList有一个无效的SelectedValue 因为它不在项目列表中“[/color]
奇怪的是,我已经做了ddl.Items.Clear();和重设SelectedIndex 处理,ddl.DataBind();的时候依然出这个错误。
请各位帮忙出主意,加班中,很急。。。
private int BindDLL(Property pro,DropDownList ddl,bool isFahter,int ppr_id,int fatherId)
{
[color=#FF0000]ddl.Items.Clear();
if(ddl.Items.Count > 0)
ddl.SelectedIndex = 0;
else
ddl.SelectedIndex = -1;[/color]
if(ppr_id!=0)
ddl.DataSource = BPropertyValues.GetListByRelation(ppr_id, fatherId);
else
ddl.DataSource = BPropertyValues.GetExtendValues(pro.Property_ID, 1);
if(isFahter)
{
ddl.SelectedIndexChanged += new EventHandler(ddlInput_SelectedIndexChanged);
ddl.AutoPostBack = true;
}
[color=#FF0000]ddl.DataBind();[/color]//这里第一次绑定没错,第二次绑定出错
if(pro.Pro_IsMust == 0)
{
ListItem item = new ListItem();
item.Text = "--请选择--";
item.Value = "0";
ddl.Items.Insert(0, item);
ddl.SelectedIndex = 0;
}
else if(ddl.Items.Count>0)
ddl.SelectedIndex = 0;
if(PageType == "update")
{
if(TM.TP_List.ContainsKey(pro.Property_ID.ToString()))
{
ListItem item = new ListItem(TM.TP_List[pro.Property_ID.ToString()].TP_Value, TM.TP_List[pro.Property_ID.ToString()].PropertyValues_ID.ToString());
if(pro.Pro_IsMust == 0)
{
if(!ddl.Items.Contains(item))
{
ddl.Items.Insert(1, item);