Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding a Datagrids column in ASP.NET(VB) 1

Status
Not open for further replies.

StuckInTheMiddle

Programmer
Mar 3, 2002
269
US
Hi,

I'm trying to hide the first 3 columns (out of 8) of a datagrid which i have bound to my resultset returned from my database (Oracle in this case).

Retrieving the data is fine, but an attempt to hide the columns following the advice in other posts here at tek-tips gives me a 'Index was out of range' error.

Dim DbConnection As New OracleConnection(f_strDbConnectString)
Dim cmdReport As New OracleCommand("select * from temp_report where issue='111150'", DbConnection)
Dim daOracle As New OracleDataAdapter()
Dim dsResults As New DataSet()

DbConnection.Open()
daOracle.SelectCommand = New OracleCommand(cmdReport.CommandText, DbConnection)
daOracle.Fill(dsResults)


grdMain.DataSource = dsResults.Tables(0)
grdMain.DataBind()
DbConnection.Close()

grdMain.Columns(0).Visible = False


All works well, the results get populated intot he table fine, but then trying to the last line fails no matter which column i try to hide.

I miss doing things in plain simple ASP so much, sniff. Any ideas?
 
I'm curious, if you debug on the code, stop it before you hit that line, and ask in the quickWatch:

grdMain.Columns.Count

What does it return?
penny1.gif
penny1.gif
 
It returns 0 isn't that wierd?

Because It clearly has a column visible for each col i'm returning from my database table.

I've not come across something like this in original ASP, im beginning to think it is something to do with using the Oracleclient and returning a resultset that way, maybe i'll try the OLEDB method of connecting to Oracle to see if that helps. If you have another idea, please don;t hold back i need all the help i can get with .NET!
 
No, what you need to do is not "autoGenerate" your columns.

You lose control over the columns when you populate a datagrid that way.

Instead, define your
<columns>
collection using
<asp:boundcolumn>s
or
<asp:templatecolumn>s

to manually define your columns -- then you will gain the control that you need.

:)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top