1

我的 GridViews 连接到它们各自的 LinqDataSource(LinqDataSourceMale & LinqDataSourceFemale) 是

<asp:GridView ID="GridViewMale" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ID" ForeColor="Black" GridLines="Horizontal" PageSize="5" Width="692px" DataSourceID="LinqDataSourceMale">
            <Columns>
                <asp:ImageField DataImageUrlField="Image" NullImageUrl="images/bullet.png" ReadOnly="True">
                </asp:ImageField>
                <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Education" HeaderText="Education" SortExpression="Education" />
                <asp:BoundField DataField="CurrentStatus" HeaderText="CurrentStatus" SortExpression="CurrentStatus" />
                <asp:BoundField DataField="Height" HeaderText="Height" SortExpression="Height" />
                <asp:BoundField DataField="Complexion" HeaderText="Complexion" SortExpression="Complexion" />
                <asp:BoundField DataField="Caste" HeaderText="Caste" SortExpression="Caste" />
                <asp:BoundField DataField="Group" HeaderText="Group" SortExpression="Group" />
            </Columns>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F7F7F7" />
            <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
            <SortedDescendingCellStyle BackColor="#E5E5E5" />
            <SortedDescendingHeaderStyle BackColor="#242121" />
        </asp:GridView>
        <asp:LinqDataSource ID="LinqDataSourceMale" runat="server" ContextTypeName="MB.BerouDataContext" EntityTypeName="" TableName="Males">
        </asp:LinqDataSource>
        <asp:GridView ID="GridViewFemale" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ID" ForeColor="Black" GridLines="Horizontal" PageSize="5" Width="693px" DataSourceID="LinqDataSourceFemale">
            <Columns>
                <asp:ImageField DataImageUrlField="Image" >
                </asp:ImageField>
                <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Education" HeaderText="Education" SortExpression="Education" />
                <asp:BoundField DataField="CurrentStatus" HeaderText="CurrentStatus" SortExpression="CurrentStatus" />
                <asp:BoundField DataField="Height" HeaderText="Height" SortExpression="Height" />
                <asp:BoundField DataField="Complexion" HeaderText="Complexion" SortExpression="Complexion" />
                <asp:BoundField DataField="Caste" HeaderText="Caste" SortExpression="Caste" />
                <asp:BoundField DataField="Group" HeaderText="Group" SortExpression="Group" />
            </Columns>
            <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
            <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Center" Wrap="True" />
            <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F7F7F7" />
            <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
            <SortedDescendingCellStyle BackColor="#E5E5E5" />
            <SortedDescendingHeaderStyle BackColor="#242121" />
        </asp:GridView>
        <asp:LinqDataSource ID="LinqDataSourceFemale" runat="server" ContextTypeName="MB.BerouDataContext" EntityTypeName="" TableName="Females">
        </asp:LinqDataSource>

我的 SearchClick 事件代码是:

 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();
                  string caste = DropDownListCaste.Text.ToString();
                  string city = DropDownListCity.ToString();

                  var SearchResultBoys = Data.Males.Where(tan =>
                      (tan.Age == age)
                      && (tan.Education.Contains(education))
                      && (tan.Group.Contains(maritalstatus))
                      && (tan.Caste.Contains(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.Contains(education))
                      && (tan.Group.Contains(maritalstatus))
                      && (tan.Caste.Contains(caste)));

                  GridViewFemale.DataSourceID = "";
                  GridViewFemale.DataSource = SearchResultGirls;
                  GridViewFemale.DataBind();



              }
        }
    }

我无法在gridview中显示数据,searchClickEvent后gridview不出现,请帮助。

4

1 回答 1

0

我认为您可能需要重新初始化您的 LinqDataSource 数据源而不是 gridview

看看这个教程和这个线程

于 2013-03-29T08:56:53.547 回答