2010-04-18 61 views
0

我做了從數據庫中填充它的值的下拉列表 但是當它運行它不會得到第一排並獲得其他人,如果我添加新它得到它 是什麼問題?dropdownlist預計第一排

private void LoadWithCategory() 
{ 
    if (Request.QueryString["Category_Id"] != null) 
    { 
     using (SqlConnection Con = Connection.GetConnection()) 
     { 
      SqlCommand Com = new SqlCommand("GetProducFamilyTP", Con); 
      Com.CommandType = CommandType.StoredProcedure; 
      Com.Parameters.Add(
       Parameter.NewInt("@Category_Id", Request.QueryString["Category_Id"])); 
      SqlDataReader DR = Com.ExecuteReader(); 

      if (DR.Read()) 
      { 
       DDLProductFamily.DataSource = DR; 
       DDLProductFamily.DataTextField = "Name"; 
       DDLProductFamily.DataValueField = "ProductCategory_Id"; 
       DDLProductFamily.DataBind(); 
      } 
      else 
      { 
       DDLProductFamily.Visible = false; 
      } 
     } 
    } 
} 
+0

你能後的代碼填充這個下拉?沒有它就不可能說出來。 – 2010-04-18 11:59:57

+0

看到我的問題,我通過查詢字符串 有我的代碼 – Myworld 2010-04-18 13:16:54

回答

0

試試這個,檢查你的代碼工作或不

 protected void DPBind(ArrayList list) 
    { 
      list.Insert(0, "your First Item"); 
      dropdownlist1.datasource = list; 
      dropdownlist1.dataBind(); 
    } 
+0

我那個 保護無效DDLProductFamily_DataBound(對象發件人,EventArgs的) { DDLProductFamily.Items.Insert(0,新的ListItem( 「過濾器產品分類」, 「0」)); } – Myworld 2010-04-18 13:18:11

+0

那麼你的問題是什麼? – 2010-04-19 06:15:03

0

請向我們顯示您的代碼。你如何將項目添加到DropDown列表?記住,集合等第一項是在索引0,而不是1.我敢打賭,你正在添加項目,以DropDownList.Add.Item(YourItem [1])開始,而不是YourItem [0]。

+0

保護無效DDLProductFamily_DataBound前 填充下拉列表發送(對象發件人,EventArgs的){ DDLProductFamily.Items.Insert(0,新的ListItem(「濾波器產品分類」,「 0" )); } – Myworld 2010-04-18 13:27:57