2014-02-27 19 views
0

我有一個asp組合框內的更新面板與autopost回設置爲true。
在頁面加載我填組合框中​​Combobox'OnSelectedIndexChanged'沒有觸發某些值

public DataTable getProductDetails() 
{ 
    MasterAllocationDB dataHandler = new MasterAllocationDB(); 
    DataTable dataBoxType = null; 
    DataRow row = null; 
    try 
    { 
     dataBoxType = dataHandler.GetBoxType(); 
     if (dataBoxType != null && dataBoxType.Rows.Count > 0) 
     { 
      row = dataBoxType.NewRow(); 
      row["Product"] = "--Select--"; 
      dataBoxType.Rows.InsertAt(row,0); 
      row = dataBoxType.NewRow(); 
      row["Product"] = "Other"; 
      dataBoxType.Rows.InsertAt(row, dataBoxType.Rows.Count); 
     } 
    } 
    catch (Exception ex) 
    { 
     LogHandler.LogMessageToFile(ex, LogMode.Fatal); 
    } 

    return dataBoxType; 
} 

另外我有一個onselectedindexchanged事件綁定

protected void productComboBox_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      string json = null; 
      List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); 
      Dictionary<string, object> row = null; 
      var s = this.productComboBox.SelectedValue; 
      try 
      { 
       int totalNoOfItems = this.productComboBox.Items.Count; 

       // Make sure that Index are between "select a value" and "Other" 
       if (this.productComboBox.SelectedIndex > 0 && this.productComboBox.SelectedIndex < totalNoOfItems - 1) 
       { 
        //code here 
       } 
       json = new JavaScriptSerializer().Serialize(rows); 


      } 
      catch (Exception ex) 
      { 
       LogHandler.LogMessageToFile(ex, LogMode.Fatal); 
      } 

     } 

正如你可以看到我已經添加了2個額外的行除了從DB.The數據獲取的行行是正確綁定,因爲我可以看到相同的輸出組合框中的值

運行後,我注意到,只要我選擇「其他」,組合框中的文本變得更改
爲「 - 選擇 - 」和控制永不到達onselectedindexchanged

它適用於所有其他情況。可能是什麼原因?

+0

你可以顯示'onselectindexchanged'的代碼嗎? – sr28

+0

@ sr28增加了它的問題 –

回答

0

好吧,我整理出來。
問題是我只爲組合框設置了文本而不是選項的值。

改變了代碼作爲

row["Product"] = "--Select--"; 
    row["ProductID"] = "0"; 

    row["Product"] = "Other"; 
    row["ProductID"] = "10"; 

產品編號給出了組合框的值。
快樂編碼