We help IT Professionals succeed at work.
Get Started

assign Gridview with 2 datasources

Last Modified: 2013-11-25
Hi problem solvers,

I have a gridview in aspx page.I have a Sqldatasource defined on it to show all customers in the customers table.I have defined this SQlDatasource in aspx page(using smart tag).
Now I included a search criteria .I simply put a textbox and a search button.When i click on the search button, i have inluded the code behind, which i have shown in code snippet:

 I get the error :Both DataSource and DataSourceID are defined on 'GrdCustomer'.  Remove one definition.

I'm missing something here in the code. I have defined a different selectcommand for the datasource.
how to Define two datasource on same Gridview
Can you tell me..whats wrong??!!!!


Any help appreciated.
Protected Sub BtnCustSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnCustSearch.Click
        Dim StrCustomerCheck As String
        Dim CmdCustometSearch As New SqlCommand
        Dim SerachValue = txtSearchCustomer.Text
StrCustomerCheck = "Select Customers.Customerid,Customers.Companyname As Company,Customers.City,Customers.State,StateProvince.Countryregionname as Country from Customers,Stateprovince where Customers.Stateprovinceid=StateProvince.Stateprovinceid and CompanyName LIKE '%SerachValue%' order By CompanyName ASC"
SQlCustomers.SelectCommand = StrCustomerCheck
 GrdCustomer.DataSource = SQlCustomers

Open in new window

Watch Question
This problem has been solved!
Unlock 2 Answers and 27 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE