如何根据需要在ListView中显示来自两个不同SQL表的数据

时间:2013-06-05 16:51:08

标签: c# asp.net linq listview dataset

我有一个ListView和一个包含两个表的数据库,我有一个Linq搜索查询,当一个人选择了新郎单选按钮并点击搜索时,它必须将来自Male表的数据显示到ListView 当人选择新娘单选按钮并点击搜索时,它应显示ListView中女表的数据我该如何管理

protected void ButtonSearch_Click(object sender, EventArgs e)
    {
        using (WebTechManiaDataContext Data = new WebTechManiaDataContext())
        {
            string Education = DropDownListEducation.SelectedItem.Text.ToString();
            string MaritalStatus = DropDownListMaritalStatus.SelectedItem.Text.ToString();

            if (RadioButtonGroom.Checked == true | RadioButtonBride.Checked == false)
            {
                if ((DropDownListFrom.SelectedItem.Text == "21") && (DropDownListTo.SelectedItem.Text == "22"))
                {
                    var FoundGroom = Data.Males.Where(Males => (Males.Age == 21 || Males.Age == 22) && (Males.Education == Education || Education.Length == 0) && (Males.CurrentStatus == MaritalStatus || MaritalStatus.Length == 0));
                    if (!FoundGroom.Any())
                    {
                        Response.Write("<script>alert('Search result Negetive');</script>");
                    }
                    else
                    {
                        ListViewResult.DataSourceID = "LinqDataSourceGroom";
                        ListViewResult.DataSource = FoundGroom;
                        ListViewResult.DataBind();
                    }
                }
                else if ((DropDownListFrom.SelectedItem.Text == "21") && (DropDownListTo.SelectedItem.Text == "23"))
                {
                    var FoundGroom = Data.Males.Where(Males => (Males.Age == 21 || Males.Age == 22 || Males.Age == 23) && (Males.Education == Education || Education.Length == 0) && (Males.CurrentStatus == MaritalStatus || MaritalStatus.Length == 0));
                    if (!FoundGroom.Any())
                    {
                        Response.Write("<script>alert('Search result Negetive');</script>");
                    }
                    else
                    {
                        ListViewResult.DataSourceID = "LinqDataSourceGroom";
                        ListViewResult.DataSource = FoundGroom;
                        ListViewResult.DataBind();
                    }
                }

                else if ((DropDownListFrom.SelectedItem.Text == "21") && (DropDownListTo.SelectedItem.Text == "24"))
                {
                    var FoundGroom = Data.Males.Where(Males => (Males.Age == 21 || Males.Age == 22 || Males.Age == 23 || Males.Age == 24) && (Males.Education == Education || Education.Length == 0) && (Males.CurrentStatus == MaritalStatus || MaritalStatus.Length == 0));
                    if (!FoundGroom.Any())
                    {
                        Response.Write("<script>alert('Search result Negetive');</script>");
                    }
                    else
                    {
                        ListViewResult.DataSourceID = "LinqDataSourceGroom";
                        ListViewResult.DataSource = FoundGroom;
                        ListViewResult.DataBind();
                    }
                }
            }
            else if (RadioButtonBride.Checked == true | RadioButtonBride.Checked == false)
            {
                if ((DropDownListFrom.SelectedItem.Text == "21") && (DropDownListTo.SelectedItem.Text == "22"))
                {
                    var FoundBride = Data.Females.Where(Females => (Females.Age == 21 || Females.Age == 22) && (Females.Education == Education || Education.Length == 0) && (Females.CurrentStatus == MaritalStatus || MaritalStatus.Length == 0));
                    if (!FoundBride.Any())
                    {
                        Response.Write("<script>alert('Search result Negetive');</script>");
                    }
                    else
                    {
                        ListViewResult.DataSourceID = "LinqDataSourceBride";
                        ListViewResult.DataSource = FoundBride;
                        ListViewResult.DataBind();
                    }
                }
                else if ((DropDownListFrom.SelectedItem.Text == "21") && (DropDownListTo.SelectedItem.Text == "23"))
                {
                    var FoundBride = Data.Females.Where(Females => (Females.Age == 21 || Females.Age == 22 || Females.Age == 23) && (Females.Education == Education || Education.Length == 0) && (Females.CurrentStatus == MaritalStatus || MaritalStatus.Length == 0));
                    if (!FoundBride.Any())
                    {
                        Response.Write("<script>alert('Search result Negetive');</script>");
                    }
                    else
                    {
                        ListViewResult.DataSourceID = "LinqDataSourceBride";
                        ListViewResult.DataSource = FoundBride;
                        ListViewResult.DataBind();
                    }
                }

                else if ((DropDownListFrom.SelectedItem.Text == "21") && (DropDownListTo.SelectedItem.Text == "24"))
                {
                    var FoundBride = Data.Females.Where(Females => (Females.Age == 21 || Females.Age == 22 || Females.Age == 23 || Females.Age == 24) && (Females.Education == Education || Education.Length == 0) && (Females.CurrentStatus == MaritalStatus || MaritalStatus.Length == 0));
                    if (!FoundBride.Any())
                    {
                        Response.Write("<script>alert('Search result Negetive');</script>");
                    }
                    else
                    {
                        ListViewResult.DataSourceID = "LinqDataSourceBride";
                        ListViewResult.DataSource = FoundBride;
                        ListViewResult.DataBind();
                    }
                }
            }
        }

0 个答案:

没有答案