Datagrid editing and databinding

jccorner

Centurion
Joined
Jan 31, 2004
Messages
144
Morning,

I'm currently working on a web app that utilizes the datagrid data component. So, first I created a table, inserted a few textboxes, labels and one datagrid. I then edited the columns for the datagrid using the propoerties manager. Lastly, I added the following code to bind the data to the datagrid:

Code:
Private Sub Page_Load

      connstr = ConfigurationSettings.AppSettings("DBBASE")
      myConn = New OleDbConnection(connstr)
      ODA = New OleDbDataAdapter("Select * From LifeTable", myConn)
      ODA.Fill(ds, "Life Offer")
      dgQuote.Datasource = ds
      dgQuote.DataBind()

End Sub

As you can see dgQuote is my datagrid but I wish to know two things:

1. When the page loads, the datagrid displays but the textboxes and labels are not visible (yes, I've checked their properties). But when I take the dgQuote.DataBind() statement out, the textboxes and labels appear but the datagrid does not appear (I would think because it has no data in it). My first question is why is this happening?? Is there a setting I'm missing??

2. When the statement dgQuote.DataBind() is left in, the datagrid appears filled with data but the datagrid contains columns for every field in the database table. How can I edit which columns to show and which ones not to, I know in my windows apps I could use the DataGridTableStyle but apparently, it is not available in the web app.

Appreciate any help anyone can provide.
 
eramgarden, thanks, but that doesn't help me.

Also, I have fixed the first issue with the textboxes and labels, how can I set the columns of the datagrid.
 
I think that's because u have "select * from .."

Specify the columns u want to be displayed instead of doing a select *.
 
When you're formating your datagrid, theres a checkbox that says 'generate columns at runtime'. Uncheck this checkbox and add as much as you want bound columns, give them header names, and specify the their table field
 
Back
Top