GridView

GridView

am 23.01.2008 21:48:59 von Rodrigo Ferreira

How do I show some data in a gridview without data binding?I mean i want to
add this by my self on runtime.

Re: GridView

am 24.01.2008 02:26:17 von Alvin Bruney

The gridview can bind to any datasource implementing idatasource such as a
dataset. Fill the dataset manually and bind to the gridview.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------



"Rodrigo Ferreira" wrote in message
news:OAO%23IFgXIHA.5816@TK2MSFTNGP06.phx.gbl...
> How do I show some data in a gridview without data binding?I mean i want
> to add this by my self on runtime.
>

Re: GridView

am 24.01.2008 02:30:51 von Joshua Starr

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.

Let me know if this helps.

Joshua

"Rodrigo Ferreira" wrote in message
news:OAO%23IFgXIHA.5816@TK2MSFTNGP06.phx.gbl...
> How do I show some data in a gridview without data binding?I mean i want
> to add this by my self on runtime.
>

Re: GridView

am 24.01.2008 12:55:06 von rodoopus

Rodrigo

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)

'ProductName
bf = New BoundField
bf.DataField = "ProductName"
bf.HeaderText = "Product"
GridView1.Columns.Add(bf)

'ContactName
bf = New BoundField
bf.DataField = "supplierid"
bf.HeaderText = "Supplier ID"
GridView1.Columns.Add(bf)

''ContactTitle
'bf = New BoundField
'bf.DataField = "Phone"
'bf.HeaderText = "Phone"
'GridView1.Columns.Add(bf)

End Sub

You can create command field dynamically, data columns and even template
fields.

Hope this helps

--
aaa


"Joshua Starr" wrote:

> 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.
>
> Let me know if this helps.
>
> Joshua
>
> "Rodrigo Ferreira" wrote in message
> news:OAO%23IFgXIHA.5816@TK2MSFTNGP06.phx.gbl...
> > How do I show some data in a gridview without data binding?I mean i want
> > to add this by my self on runtime.
> >
>
>