Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need both form level and Code Behind Gridview VB.NET

    Hey, guys question for you. I am getting an error, both datasource and datasourceID defined, please remove one of them. what I am trying to do is to set default values for a gridview from the pageload event and also allow the form level usage of datasourceID to set data inside the gridview. I am trying to set the data inside the pageload event, how do I do these without triggering this error? I have tried to remove the DatasourceID reference but then I cannot set it back without causing another error or else not getting it back to form level. Any ideas?

    'Open up the connection

    SQLConnection.Open()

    'HERE WE NEED TO SET INITIAL GRIDVIEW VALUES
    Gridview1.DataSource = Nothing
    Gridview1.DataSourceID = Nothing
    Gridview1.DataBind()
    Dim dsGridViewData As DataSet = New DataSet
    Dim daGridview As SqlDataAdapter = New SqlDataAdapter()

    'GET ACTUAL BASE PERSON FROM SELECTED INDEX IN GRIDVIEW
    Dim sqlStrGridView As String = "SELECT *" & _
    "FROM TblDotNetAncestorsTree where uniqueID = '" & "12334546456" & "'"

    daGridview = New SqlDataAdapter(sqlStrGridView, SQLConnection)
    daGridview.Fill(dsGridViewData)

    Gridview1.DataSource = dsGridViewData

    Gridview1.DataSource = Nothing
    Gridview1.DataSourceID = "SqlDataSourceGridView"

    Here I would like to set it back so that it is usable at the form level, but its not working, any ideas?

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,805
    Thanks
    41
    Thanked 199 Times in 198 Posts
    just don't set anything- if you are going to set anything set it's visibility to false... without the error messages or a clear explanation of what you are attempting will not be able to help. (what is it you're trying to do- I do not understand. What are the error messages?)

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •