...

View Full Version : Need both form level and Code Behind Gridview VB.NET



coxmg
06-04-2012, 07:21 PM
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?

alykins
06-05-2012, 06:27 PM
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?)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum