我有一个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();
}
}
}
}