private void Bind()
        {
            int pid = int.Parse(this.Request.QueryString["pid"].ToString());
            DataRow row = pro.getoneproduct(pid);
            this.productnameliteral.Text = row["productname"].ToString();
            this.ltProductorders.Text = row["productorders"].ToString();
            this.IMG1.Src = "pic/" + row["imagepath"].ToString();
            this.IMG1.Alt = "pic/" + row["imagepath"].ToString();
            this.type_1nameliteral.Text = t_1.gettypename(int.Parse(row["typeid_1"].ToString()));
            this.type_2nameliteral.Text = t_2.gettypename(int.Parse(row["typeid_2"].ToString()));
            this.pointcountliteral.Text = row["pointcount"].ToString();
            this.countliteral.Text = (int.Parse(row["count"].ToString()) > int.Parse(row["sellcount"].ToString())) ? row["count"].ToString() : "缺货";
            this.sellcountliteral.Text = row["sellcount"].ToString();
            this.priceliteral.Text = row["price"].ToString();
            this.userpriceliteral.Text = row["userprice"].ToString();
            this.specialsliteral.Text = row["specialsprice"].ToString();
            this.descriptionliteral.Text = row["description"].ToString();
            
                this.drpColor.DataSource = row["pcolor"].ToString().Split(',');
                this.drpColor.DataBind();            this.drpSize.DataSource = row["psize"].ToString().Split(',');
            this.drpSize.DataBind();            this.drpColor.Items.Insert(0, new ListItem("=请选择颜色=", "0"));
            this.drpSize.Items.Insert(0, new ListItem("=请选择尺寸=", "0"));        }

解决方案 »

  1.   

    空行? 是不是空选项? 你在绑定的时候做下判断,把空项移除另外:
    this.drpColor.Items.Insert(0, new ListItem("=请选择颜色=", "0")); 
    this.drpSize.Items.Insert(0, new ListItem("=请选择尺寸=", "0")); 
    这2句没必要写,你只要直接在drpColor、drpSize控件里分别添加"=请选择颜色="、"=请选择尺寸="2个项,但是要把dropdownlist的AppendDataBoundItems属性改成true就可以了,2005新增的功能
      

  2.   

    是这样的,我在后台是是文本框的值,然后在前台显示是在dropdownlist里面,我现在把它的,号去掉了,也把他分成了多个项,但就是最后一项是空的,请问我在上面该如何判断啊,谢谢了
      

  3.   

    this.drpColor.DataSource = row["pcolor"].ToString().Split(','); 
    this.drpColor.DataBind(); row["pcolor"].ToString() 这个值是什么?
    如果 string s = "a,b,c,d,e,f"; 这样就没问题
    但如果string s = "a,b,c,d,e,f,";这样就会多出一个空项,你只要把最好一个,去掉就可以了代码:s = s.TrimEnd(',');