我在我的页面上放置了一个 gridview 并将其链接到 LinqDataSourceFemale(数据库的女性表),并且我有一个类似下面的搜索事件代码
protected void ButtonSearch_Click(object sender, EventArgs e)
{
using(BerouDataContext Data = new BerouDataContext())
{
if (DropDownListGender.SelectedItem.Text == "Male")
{
int age = Convert.ToInt32(DropDownListAge.Text);
string education = DropDownListEducation.Text.ToString();
string maritalstatus = DropDownListMaritalStatus.Text.ToString();
//var religion = DropDownListReligion.Text.ToString();
string caste = DropDownListCaste.Text.ToString();
string city = DropDownListCity.ToString();
var SearchResultBoys = Data.Males.Where(tan =>
(tan.Age == age)
&& (tan.Education == education)
&& (tan.Group == maritalstatus)
&& (tan.Caste == caste));
GridViewMale.DataSourceID = "";
GridViewMale.DataSource = SearchResultBoys;
GridViewMale.DataBind();
}
else if (DropDownListGender.SelectedItem.Text == "Female")
{
int age = Convert.ToInt32(DropDownListAge.Text);
string education = DropDownListEducation.Text.ToString();
string maritalstatus = DropDownListMaritalStatus.Text.ToString();
//var religion = DropDownListReligion.Text.ToString();
string caste = DropDownListCaste.Text.ToString();
string city = DropDownListCity.ToString();
var SearchResultGirls = Data.Females.Where(tan =>
(tan.Age == age)
&& (tan.Education == education)
&& (tan.Group == maritalstatus)
&& (tan.Caste == caste));
GridViewFemale.DataSourceID = "";
GridViewFemale.DataSource = SearchResultGirls;
GridViewFemale.DataBind();
}
}
}
单击按钮后不出现网格视图,请帮助我。