Solved

GridView DataSource and DataSource ID

Posted on 2006-06-12
4
881 Views
Last Modified: 2012-06-27
Protected Sub SearchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchButton.Click
        GridViewComp.Visible = True
        Dim queryString As String = _
          "SELECT cage, company, compcity, compst, comppoc, compphone FROM company WHERE " & DropDownList1.SelectedValue & " LIKE '%" & TextBox1.Text & "%'"
        Dim ds As Data.DataSet = GetData(queryString)

        If (ds.Tables.Count > 0) Then
            'If (ds.Tables.Count > 0) Then

            GridViewComp.DataSource = ds
            GridViewComp.DataBind()

        Else

            MsgBox("Unable to connect to the database.")

        End If

    End Sub

    Function GetData(ByVal queryString As String) As Data.DataSet

       Dim connectionString As String = ConfigurationManager.ConnectionStrings("SecConConnectionString").ConnectionString
        Dim ds As New Data.DataSet()

        Try
            Dim connection As New Data.SqlClient.SqlConnection(connectionString)
            Dim adapter As New Data.SqlClient.SqlDataAdapter(queryString, connection)
            adapter.Fill(ds)
        Catch ex As Exception
            MsgBox("Unable to connect to the database.")
        End Try

        Return ds

    End Function

I get an Error Msg:   Both DataSource and DataSourceID are defined on 'GridViewComp'.  Remove one definition.
It breaks at GridViewComp.DataBind()
What do I need to do?
0
Comment
Question by:marcivry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:razorback041
ID: 16890637
check your properties window of your gridview....and see if you have the datasourceid assigned to a datasource there...if so, remove it
0
 

Author Comment

by:marcivry
ID: 16893417
When I take out the datasource information, since I can't take out the datasource ID, an error occurs when I do, the information comes up on the grid, but when I want to sort or page, I get an error now.

The GridView 'GridViewComp' fired event Sorting which wasn't handled.

So I think I have a catch-22. Either I can't sort or page or don't have the gridview. Any suggestions?
0
 
LVL 5

Accepted Solution

by:
razorback041 earned 300 total points
ID: 16898871
Here ya go...this is for sorting manually when bound to a dataset...

http://gridviewguy.com/ArticleDetails.aspx?articleID=176
0
 

Author Comment

by:marcivry
ID: 17045531
Thanks. But I ended up using something else.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question