hiding a Datagrid column

S

samuel Mesel

I'm developing an ASP.NET application. I have a datagrid that has
7 columns. The first 3 columns contain buttons (Select, Edit, and Delete)
The next 4 contain data (Table name, Change Description, Change Date,
and Table ID). I need to have the Table ID of the user's selected
table - I use it later when I go to edit or delete the table. (The
editing is done on a seperate screen because the description field i
larger than I want to fit into a datagrid). But, I would like to hide
the Table ID column - the user does not need to see it.

I have a problem trying to set the column's visible property to false
When I run the page with the code:
Datagrid.Columns(6).visible = Fals
I receive an error that the index is out of range. I receive the sam
error if I try to blank out columns 3,4, or 5. The only time it work
correctly is when I blank out columns 0, 1, or 2 (the button columns)
I created the button columns using the Datagrid Property Builder in th
Visual Studio.NET IDE.

Any idea how I can get the visible property to work on the non-butto
columns
 
O

Omar Squiabro\(ETSD Corp.\)

' Visual Basic
DataGrid1.Columns(1).Visible = Not (DataGrid1.Columns(1).Visible)

// C#
DataGrid1.Columns[1].Visible = !(DataGrid1.Columns[1].Visible);

--
Omar Squiabro
Enterprise Technologies & Software Design
Project Manager
www.etsdpr.com
Tel. 1-787-644-5981
 
S

samuel Mesel

Omar
Thanks for your reply, but you didn't see my whole descriptio. If you read it through, you'll notice that I mention I tried to do what you suggested and it didn't work...
I'm trying to hide one of the data columns, if I do it it will be able to hide one of the command-buttons, or it gives me an error

Sa
 
S

samuel Mesel

Hi Eliyahu

Please see the following code

I create a data table (odt) and a data row (odr). I use a data reader t
retrieve records from the database. I then add column headers to the
data table through statements such as

odt.Columns.Add(New DataColumn("Table Name", GetType(String))

I loop through the retrieved records, and for each one, I
create a new data row:
odr = odt.NewRow(
put each of the 4 data fields into the data row
odr(0) = datareader(0
odr(1) = datareader(1)
etc
add the data row to the data table
odt.Rows.Add(odr

Finally, I put the data from the DataTable into the DataGrid as follows
Dim odv As New DataView(odt
datagrid.DataSource = od
datagrid.DataBind(
 
E

Eliyahu Goldin

Samuel,

Make sure that datagrid.AutoGenerateColumns is set to true. If it is not,
you have to create the columns of the datagrid yourself, either in design or
run time, with specifying DataField property for each column.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top