使用Linq中第一个DDL的值填充DDL

时间:2012-08-24 18:26:34

标签: c# linq

我使用国家/地区DDL中的文本填写州DDL

   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;

    }

1 个答案:

答案 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();
    }
}