Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > hiding a Datagrid column

Reply
Thread Tools

hiding a Datagrid column

 
 
samuel Mesel
Guest
Posts: n/a
 
      05-21-2004
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

 
Reply With Quote
 
 
 
 
Omar Squiabro\(ETSD Corp.\)
Guest
Posts: n/a
 
      05-21-2004
' 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
"samuel Mesel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 is
> 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 = False
> I receive an error that the index is out of range. I receive the same
> error if I try to blank out columns 3,4, or 5. The only time it works
> 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 the
> Visual Studio.NET IDE.
>
> Any idea how I can get the visible property to work on the non-button
> columns?
>



 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-23-2004
How do you create the last 4 columns?

Eliyahu

"samuel Mesel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 is
> 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 = False
> I receive an error that the index is out of range. I receive the same
> error if I try to blank out columns 3,4, or 5. The only time it works
> 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 the
> Visual Studio.NET IDE.
>
> Any idea how I can get the visible property to work on the non-button
> columns?
>



 
Reply With Quote
 
samuel Mesel
Guest
Posts: n/a
 
      05-25-2004
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


 
Reply With Quote
 
samuel Mesel
Guest
Posts: n/a
 
      05-25-2004
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(

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-27-2004
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

"samuel Mesel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Eliyahu,
>
> Please see the following code:
>
> I create a data table (odt) and a data row (odr). I use a data reader to
> 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 = odv
> datagrid.DataBind()
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Hiding a hyperlink in a non-databound datagrid column BobRoyAce ASP .Net 2 01-20-2005 04:24 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM
DataGrid - Hiding a Column - Not Working David Freeman ASP .Net 7 10-25-2004 07:01 AM
hiding a column of datagrid: dataset chosen at run-time Michelle Stone ASP .Net 0 10-15-2003 10:01 AM



Advertisments