2013-03-29 29 views
1

我GridView的被連接到它們各自的LinqDataSource(LinqDataSourceMale & LinqDataSourceFemale)是如何在GridView中顯示搜索數據?

<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不會返回,請幫助。

+0

我想你可能需要重新initlize您的LinqDataSource數據源,而不是的gridview –

回答

0

我想你可能需要重新initlize您的LinqDataSource數據源,而不是GridView的

this教程和this線程看看

相關問題