Solved

GridView DataSource and DataSource ID

Posted on 2006-06-12
4
876 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now