2012-08-24 25 views
0
首先DDL填寫使用值一個DDL

我填補了國家DDL使用文本在全國DDLLinq中

foreach (var VARIABLE in ProfileMasterDAL.bindcountry()) 
      { 
       if (VARIABLE.ToString().Contains(DropDownList1.SelectedItem.Text)) 
       { 
        var query = from row in ProfileMasterDAL.bindstate().ToString() 
           where 
            ProfileMasterDAL.bindstate().ToString().Contains(DropDownList1.SelectedItem.Text) 
           select row; 
        DropDownList2.DataSource = query; 
        DropDownList2.DataBind(); 
       } 
      } 

,但在查詢我得到枚舉產生任何結果,各州DDL是空的。

public static IEnumerable bindstate() 
    { 
     var states = from b in getdata().Descendants("state").SelectMany(state => state.Elements("text")) 
     orderby (string) b 
     select (string) b; 

     return states; 

    } 
+0

你設置'DataSource'一個'foreach'內,這意味着你*可能會*設置多次,這不是一個好方法。另外,您正在查看該州是否包含國名?尷尬了。最後,當你調試它時,你有沒有進入'如果'的內部? –

+0

你爲什麼試圖從字符串中選擇一些東西?這最終是針對'char []'的查詢,當然這不是你想要的? – CodingGorilla

+0

我正在尋找包含州名的國家。是的,我已經進入瞭如果條件和即時通訊有問題的查詢。 –

回答

0

好了,根據意見和更新你的問題,我想這是你想要什麼:

foreach (var VARIABLE in ProfileMasterDAL.bindcountry()) 
{ 
    if (VARIABLE.ToString().Contains(DropDownList1.SelectedItem.Text)) 
    { 
     var query = from row in ProfileMasterDAL.bindstate() 
        where row.Contains(DropDownList1.SelectedItem.Text) 
        select row; 
     DropDownList2.DataSource = query; 
     DropDownList2.DataBind(); 
    } 
} 
+0

事情是,我無法得到where子句並且包含智能感知無法顯示它們。 –

+0

由於您的'bindstate()'方法剛剛返回一個'IEnumerable',因此您無法獲得IntelliSense,因此IntelliSense無法檢查並提供更多信息。如果您更改該方法以返回'IEnumerable ',您將獲得更多信息。 – CodingGorilla

+0

當我改變返回XElement的方法時,由於無法將類型'System.Collections.Generic.IEnumerable '隱式轉換爲'System.Collections.Generic.IEnumerable 」。存在明確的轉換(你是否缺少演員?) –