troubleshooting Question

assign Gridview with 2 datasources

Avatar of SaraDob
SaraDob asked on
Microsoft DevelopmentASP.NETWeb Applications.NET Programming
27 Comments2 Solutions1805 ViewsLast Modified:
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
       
        MyConn.Close()
ASKER CERTIFIED SOLUTION
DropZone

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 27 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 27 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros