Rodrigo, you can add in a datasource (SQL) but don't enter in anything for
the 'SelectCommand' ... effectively an empty datasource -- then what you can
do is in the codebehind, set the SqlDataSourceName.SelectCommand = "select
field1, field2, field3 from yourtable" and finally bind it with:
GridView1.databind.
If you mean can I setup the Gridview programmatically then the answer is Yes!
Assuming ready datasource
Dim b as new businessLayer.AppBusinessRules
Gridview1.DataSource = b.GetData()
GridView1.DataBind
Normally throw this on you Load event or you can refactor this into it own
function or sub you can call over and over again.
To be clear, the first line depicts a possible business layer (DLL) you
created that allows you get your data from wherever. Once you a say a
datatable or dataset you can manipulate the content to your hearts desire to
make things behave the way you want. Writing code makes things a little more
difficult at first but gives you flexibility and power limited only by your
imagination.
I never use the SqlDataSource or ObjDataSource in my production code
primarily because they tend to be too restrictive.
You can also define column definitions in code something like this
Imports system.Data
Imports System.Web.UI.WebControls
Private Sub GVProductColDef()
Dim cmdF As New CommandField
cmdF.EditText = "Select"
cmdF.ButtonType = ButtonType.Link
cmdF.ShowSelectButton = True
GridView1.Columns.Add(cmdF)
' ProductID
Dim bf As New BoundField
bf.DataField = "ProductID"
bf.HeaderText = "Product ID"
GridView1.Columns.Add(bf)