Hide Datagrid Column via client side scripting (Javascript)

R

Rob

Does anyone know how I could hide a column in a DataGrid? To make the
problem harder I am using AutoGenerateColumns="True" so I don't know
how to find the control using document.getElementById(ControlID) and
then hiding it by using display:none;

Anyone have any suggestions?

Thanks for the help.
 
E

Eliyahu Goldin

You know the grid id. It lets you find the table the grid is rendered as.
The first row of the table contains the column headers. If you know the
column header text, you can loop through the cells of the first row and find
the one with the innerText matching the required header text. In this way
you find out the index of the required column in the row. Then loop through
the rest of the rows and set display:none for the cell with the required
index.

Eliyahu
 
P

Patrick.O.Ige

Why don't you simply do :
yourDataGrid.Columns[columnIndex].Visible = false;
Patrick
 
E

Eliyahu Goldin

Patrick,

Firstly, autogenerated columns don't appear in Columns collection.
Secondly, the OP is looking for a client-side solution.

Eliyahu

Patrick.O.Ige said:
Why don't you simply do :
yourDataGrid.Columns[columnIndex].Visible = false;
Patrick


Rob said:
Does anyone know how I could hide a column in a DataGrid? To make the
problem harder I am using AutoGenerateColumns="True" so I don't know
how to find the control using document.getElementById(ControlID) and
then hiding it by using display:none;

Anyone have any suggestions?

Thanks for the help.
 
T

Techotsav

Rob do u mean by hiding column hiding text or hiding whatever inside
that cloumn (may be some other controls too)?
 
R

Rob

Yes, hiding the entire contents of the column in the autogenerated
datagrid. Previously I have been using .Visible=false but a round trip
to the server is too slow.

I think Eliyahu Goldin has what I am looking for however I am not sure
I know how to work through the solution. Does anyone have an example
of this?
Thanks in advance for the help.
 
P

Patrick.O.Ige

Sorry though i didn't notice the AutoGenerateColumns.

Patrick.O.Ige said:
Why don't you simply do :
yourDataGrid.Columns[columnIndex].Visible = false;
Patrick


Rob said:
Does anyone know how I could hide a column in a DataGrid? To make the
problem harder I am using AutoGenerateColumns="True" so I don't know
how to find the control using document.getElementById(ControlID) and
then hiding it by using display:none;

Anyone have any suggestions?

Thanks for the help.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top