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

  • SEARCH
  • Home
  • 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 7042615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:11:23+00:00 2026-05-28T02:11:23+00:00

The following GridView with an EntityDataSource that grabs 3 fields from the Surveyors table

  • 0

The following GridView with an EntityDataSource that grabs 3 fields from the Surveyors table (which contains more fields) works, but of course it shows me every Surveyor.

<asp:GridView ID="gvwSurveyors" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" DataSourceID="edsSurveyors">
  <Columns>
    <asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" SortExpression="FirstName" />
    <asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" SortExpression="LastName" />
    <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
  </Columns>
</asp:GridView>
<asp:EntityDataSource ID="edsSurveyors" runat="server"
  ConnectionString="name=PLSOEntities"
  DefaultContainerName="PLSOEntities"
  EnableFlattening="False"
  EntitySetName="Surveyors"
  Select="it.[FirstName], it.[LastName], it.[ID]"
  AutoGenerateOrderByClause="true">
  <OrderByParameters>
    <asp:Parameter DefaultValue="LastName" />
  </OrderByParameters>
</asp:EntityDataSource>

So in order to get the initial page load to not show everything I added the OnSelecting event to the EntityDataSource and have it cancel the query if it is Not a postback.

protected void edsSurveyors_Selecting(object sender, EntityDataSourceSelectingEventArgs e) {
  if (!Page.IsPostBack)
    e.Cancel = true;
}

I have two text boxes named txtFirstName and txtLastName that I want the user to be able to search using a SQL query LIKE style. Some reading on the web pointed me toward the QueryExtender. I changed the code to the following:

<asp:GridView ID="gvwSurveyors" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="3" DataSourceID="edsSurveyors">
  <Columns>
    <asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" SortExpression="FirstName" />
      <asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" SortExpression="LastName" />
      <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
    </Columns>
  </asp:GridView>
  <asp:EntityDataSource ID="edsSurveyors" runat="server"
    ConnectionString="name=PLSOEntities"
    DefaultContainerName="PLSOEntities"
    EnableFlattening="False"
    EntitySetName="Surveyors"
    Select="it.[FirstName], it.[LastName], it.[ID]"
    AutoGenerateOrderByClause="true" onselecting="edsSurveyors_Selecting">
    <OrderByParameters>
      <asp:Parameter DefaultValue="LastName" />
    </OrderByParameters>
  </asp:EntityDataSource>
  <asp:QueryExtender ID="qexSurveyor" runat="server" TargetControlID="edsSurveyors">
    <asp:SearchExpression SearchType="Contains" DataFields="FirstName">
      <asp:ControlParameter ControlID="txtFirstName" />
    </asp:SearchExpression>
  </asp:QueryExtender>

So now when I click the button I get the error: ‘FirstName’ is not a member of type ‘System.Data.Common.DbDataRecord’

What can I do to allow a Contains? Once it works, I will then added a LastName parameter that does the same.

  • 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-28T02:11:24+00:00Added an answer on May 28, 2026 at 2:11 am

    I also ran into the same thing when using AdventureWorks as a data source. I had to remove the ‘Select=’ from my EntityDataSource. For a workaround, I went to my GridView and set AutoGenerateColumns=”False”. I then manually added each column I wanted to display in the Gridview, e.g.

            <asp:BoundField DataField="CustomerID" HeaderText="Customer ID" />
            <asp:BoundField DataField="SalesPerson" HeaderText="Sales Person" />
            <asp:BoundField DataField="CustomerID" HeaderText="Customer ID" />
            <asp:BoundField DataField="FirstName" HeaderText="First Name" />
            <asp:BoundField DataField="LastName" HeaderText="Last Name" />
            <asp:BoundField DataField="CompanyName" HeaderText="Company Name" />
            <asp:BoundField DataField="EmailAddress" HeaderText="Email Address" />
            <asp:BoundField DataField="Phone" HeaderText="Phone" />
    

    As an additional note, it seems another workaround, albeit programatically, is to apply a LINQ Query to the EntityDataSource using the onquerycreated event. In this case, you don’t need to declaratively use the Query Extender supposedly. Full Article Here -> http://msdn.microsoft.com/en-us/library/ee404748.aspx

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

Sidebar

Related Questions

I have a GridView which has following template field that holds the filename, when
I have a gridview with following fields LECTURE ID,LECTURER NAME,SUBJECTS and gridview contains link
How to set gravity of gridview, i used the following code for that but
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I have following Gridview: <asp:GridView ID=GridView1 runat=server CssClass=table DataKeyNames=groupId DataSource=<%# dsUserGroupsSelected %> DataMember=Group etc....>
I have the following column in a GridView , and my problem is that
I'm following the example on the android tutorial about the GridView, but instead of
I have the following code which adds a label and a gridview to an
In this following gridview image.png images are taken from the drawable folder.Now I want
I have a user control that contains a GridView. I create an instance of

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.