if (!IsPostBack) {
            ZHLbookshop.Model.Books book = new ZHLbookshop.Model.Books();
            ZHLbookshop.BLL.Books bll = new ZHLbookshop.BLL.Books();
            book = bll.GetModel(int.Parse(Request.QueryString["ts_BooksId"].ToString()));            BookNameTextBox.Text = book.ts_BookName;
            tsdlDropDownList.SelectedValue = Convert.ToString(book.tsdl_TypeId);
            tsxlDropDownList.SelectedValue = Convert.ToString(book.tsxl_TypeId);
            tsxxlDropDownList.SelectedValue = Convert.ToString(book.tsxxl_TypeId);            AuthorTextBox.Text = book.ts_Author;
            PublishingTextBox.Text = book.ts_Publishing;
            PublishDateTextBox.Text = book.ts_PublishDate;
            ISBNTextBox.Text = book.ts_ISBN;
            EditionTextBox.Text = Convert.ToString(book.ts_Edition);            DropDownList1.SelectedValue= book.ts_Format;//就是这句出错了            PagesTextBox.Text = Convert.ToString(book.ts_Pages);
            PriceTextBox.Text = Convert.ToString(book.ts_Price);
            DiscountPriceTextBox.Text = Convert.ToString(book.ts_DiscountPrice);
            DiscountDropDownList.SelectedValue = book.ts_Discount;
            PicksDropDownList.Text = Convert.ToString(book.ts_Picks);
            BargainDropDownList.Text = Convert.ToString(book.ts_Bargain);
            ExclusiveDropDownList.Text = Convert.ToString(book.ts_Exclusive);            AllSumTextBox.Text = Convert.ToString(book.ts_AllSum);
            InformationTextBox.Text = book.ts_Information;
            PicksNRTextBox.Text = book.ts_PicksNR;
            
        }    }
也就是载入时,就是显示数据的
有些数据运行成功,有些运行出错,这个DropDownList1是用数据库邦定的代码如下asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="SqlDataSource5" DataTextField="ts_Format" 
                        DataValueField="ts_Format">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:ZHLbookshop1 %>" 
                        SelectCommand="SELECT * FROM [FormatType]"></asp:SqlDataSource>

解决方案 »

  1.   

    DropDownList1.SelectedValue= book.ts_Format
    book.ts_Format的内容不在 DropDownList1 的选项中。
    你应该这样
    ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
    if(x!=null) x.Selected=true;另外,这个操作是在绑定玩数据之后进行的
      

  2.   

    对不上数据库的内容,那是你的数据没有取出来
    你打印出
    book.ts_Format是什么?
    DropDownList1里面有你需要的值吗?注意是Value不是Text
    如果book.ts_Format不在你的DropDownList1里面,是不能设置的
      

  3.   

    发2个链接供你参考一下http://zhidao.baidu.com/question/91129393.htmlhttp://topic.csdn.net/u/20080626/01/ca3637ad-7672-4072-9824-7d7d19e687fb.html
      

  4.   

    这个有book.ts_Format值啊,   Label2.Text =book.ts_Format;他也有值啊,也显示正确,用
    asp:DropDownList ID="DropDownList1" runat="server" 
      DataSourceID="SqlDataSource5" DataTextField="ts_Format" 
      DataValueField="ts_Format">
      </asp:DropDownList>
      <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
      ConnectionString="<%$ ConnectionStrings:ZHLbookshop1 %>" 
      SelectCommand="SELECT * FROM [FormatType]"></asp:SqlDataSource>这个时就出错了
      

  5.   

    报告的错误信息什么?什么错误?你设置
    ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
    if(x!=null) x.Selected=true;
    是在绑定之后设置的吗?
      

  6.   

    报告的错误信息是:DropDownList1的selectvalued不在项目列表里,无效的Value的值,你说的这个
    ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
    if(x!=null) x.Selected=true;是放在哪里,是不是放在这个  
    DropDownList1.SelectedValue= book.ts_Format;//就是这句出错了
    地方,我试过放在这里没有错误,但它显示的内容与我数据库的内容不一样啊,跟不要这个DropDownList1东西是一样的
      

  7.   

    错误不是说的很清楚了吗?你设置的值不在项目列表里,怎么能够设置Selected=true呢?你要搞清楚,只有在选择列表中的才能进行设置
    另外,你要搞清楚,是Value还是Text为你的book.ts_Format的值,如果是Vlaue,使用ListItem x = DropDownList1.Items.FindByValue(book.ts_Format);
    if(x!=null) x.Selected=true;
    如果是Text则需要使用
    ListItem x = DropDownList1.Items.FindByText(book.ts_Format);
    if(x!=null) x.Selected=true;