Solved

GridView DataSource and DataSource ID

Posted on 2006-06-12
4
874 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. But I ended up using something else.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

17 Experts available now in Live!

Get 1:1 Help Now