Solved

GridView DataSource and DataSource ID

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Name space syntax error 12 56
Initial get page response times and IIS8 15 49
ASP.NET MVC -Add authentication 2 21
asp.net mvc5 6 15
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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

785 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