?
Solved

GridView DataSource and DataSource ID

Posted on 2006-06-12
4
Medium Priority
?
883 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 1200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

771 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