Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:34:38+00:00 2026-05-16T01:34:38+00:00

the problem is not solved the way i wanted but i go ahead give

  • 0

the problem is not solved the way i wanted but i go ahead give the credit to : ŁukaszW.pl for his time and effort.

i am using gridview control and a linqdatasource and its all working fine and i have added the functionlity of searchingBySubject and i added WhereParameters and than binding my gridview (see the code below) but somehow its not returning any rows and i see i have number of rows based on what i am searching.

 protected void btnSearch_Click(object sender, EventArgs e)
 {    
   this.LinqDataSource1.WhereParameters["Subject"].DefaultValue = this.txtSubject.Text;
   this.GridView1.DataBind();
 }

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  
         DataSourceID="LinqDataSource1"  
        EmptyDataText="There are no data records to display."> 
        <Columns> 
            <asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"  
                SortExpression="UserID" /> 
            <asp:BoundField DataField="Username" HeaderText="Username"  
                SortExpression="Username" /> 
            <asp:BoundField DataField="FirstName" HeaderText="FirstName"  
                SortExpression="FirstName" /> 
            <asp:BoundField DataField="LastName" HeaderText="LastName"  
                SortExpression="LastName" /> 
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /> 
        </Columns> 
    </asp:GridView> 

     <asp:LinqDataSource ID="LinqDataSource1" runat="server"  
        ContextTypeName="MyDataContextDataContext" 
        onselecting="LinqDataSource_Selecting" > 
            <WhereParameters> 
               <asp:Parameter Name="Subject" />
            </WhereParameters> 
        </asp:LinqDataSource>



public List<Reporter> GetInquiries()
        {
            using (MyDataContextDataContext dc = conn.GetContext())
            {
                var loadAll = (from spName in dc.spReporter()
                               select spName);

                List<Reporter> reporterList = new List<Reporter>();

                foreach (var item in loadAll)
                {
                    reporterList.Add(new Reporter(item.Id, item.InqDate, item.Subject));
                }                

                return reporterList;
            }      

ERROR:

 The query results cannot be enumerated more than once
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:34:39+00:00Added an answer on May 16, 2026 at 1:34 am

    About the problem, I don’t see any connection between your GetInquiries method and LinqDataSource. Thats first, second is that even if there will be connection it will not work if you are returning list, and not IQueriable object…

    To better uderstand binding with LinqDataSource read this Scott Gu’s article

    Also I want to show you that your GetInquiries method could be simplified to this form:

        public List<Reporter> GetInquiries()
        {
            using (MyDataContextDataContext dc = conn.GetContext())
            {
                return (from spName in dc.spReporter()
                        select new Reporter(spName.Id, spName.InqDate, spName.Subject)).ToList()
    
            }      
    

    —- EDITED —-

    Example of alternative solution:

        public List<Reporter> GetInquiries(string subject)
        {
            using (MyDataContextDataContext dc = conn.GetContext())
            {
                return (from spName in dc.spReporter()
                        select new Reporter(spName.Id, spName.InqDate, spName.Subject
                        where spName.Subject == subject)).ToList()
    
            }  
        }
    
        protected void btnSearch_Click(object sender, EventArgs e)
        {    
           GridView1.DataSource = GetInquiries(txtSubject.Text);
           GridView1.DataBind();
        }
    

    ———- EDIT ————-

    protected void btnSearch_Click(object sender, EventArgs e)
    {    
       this.LinqDataSource1.WhereParameters["Subject"].DefaultValue = this.txtSubject.Text;
       this.GridView1.DataBind();
    }
    
    public void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    { 
        ReporterRepository reporterRepo = new ReporterRepository();
        e.Result = reporterRepo.GetInquiries();    
    }
    
    public IQueryable<Reporter> GetInquiries()
    {
        return from spName in dc.spReporter()
               select new Reporter(spName.Id, spName.InqDate, spName.Subject);
    }     
    
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="LinqDataSource1" EmptyDataText="There are no data records to display."> 
            <Columns> 
                <asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"  
                    SortExpression="UserID" /> 
                <asp:BoundField DataField="Username" HeaderText="Username"  
                    SortExpression="Username" /> 
                <asp:BoundField DataField="FirstName" HeaderText="FirstName"  
                    SortExpression="FirstName" /> 
                <asp:BoundField DataField="LastName" HeaderText="LastName"  
                    SortExpression="LastName" /> 
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /> 
            </Columns> 
    </asp:GridView> 
    
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="MyDataContextDataContext" onselecting="LinqDataSource_Selecting"> 
            <WhereParameters> 
               <asp:Parameter Name="Subject" />
            </WhereParameters> 
    </asp:LinqDataSource>
    

    Regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not really a question because I just solved the problem, but I
The problem is not solved although I accepted one answer. Problem: Vim updates very
I have a simple problem but I am not sure how to solve it.
[Meta notes: the following question is not answered, but the problem that the question
there's this interesting problem i can not solve myself. I will be very glad,
I have a strange problem that I could not solve. When I try to
I've got a problem I'm not sure how best to solve. I have an
i'm not sure how to solve the following problem: i have a triangle with
I'm trying to solve this problem, its not a homework question, its just code
I can't solve this problem... I'm having some problems with fetched properties (not with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.