This is a migrated thread and some comments may be shown as answers.

[Solved] How hide grid column during runtime

3 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lim
Top achievements
Rank 1
Lim asked on 29 Jul 2009, 07:37 AM
Hi,
I have a grid on my web design and set the grid's DataSource during NeedDataSource event by using following syntax:

RadGrid1.MasterTableView.DataSource = myDataSet.Tables(

"a").DefaultView

 


I tried to hide the column after the grid's DataSource is set but having code break by using following syntax:

RadGrid1.Columns(0).Visible =

False

 


After that, I tried to debug it during runtime and found out that the grid having no column even though i have set its DataSource.

Anyway to solve this out?

Thanks in advance and apprciate for the answer.

Regards,
Lim

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2009, 09:40 AM
Hello Lim,

I suppose that the columns in your grid are auto generated and not added manually. If thats the case, then you would have to try the following line of code to hide the required column:
c#:
RadGrid1.MasterTableView.RenderColumns(0).Visible = False 

Thanks
Princy.
0
Lim
Top achievements
Rank 1
answered on 29 Jul 2009, 10:27 AM
Hi Princy,
Thanks for your reply.

Yes, the column in my grid is auto generated.
Let me explain my scenario again,
I will have 5 columns in my grid. I want to hide the first and the last column due to some requirement and those hiden columns values will be used in the future.

I have tried your suggestion, the column i wanted to hide is still appearing. But the good news is no more code break.

Any alternative way to solve this?

Thanks.

For your info,
I put a breakpoint at the line of code suggested by you, i found out that the RadGrid1.MasterTableView.RenderColumns having index of 2:
(0) - {Telerik.Web.UI.GridExpandColumn}
(1) - {Telerik.Web.UI.GridRowIndicatorColumn}

0
Lim
Top achievements
Rank 1
answered on 30 Jul 2009, 08:02 AM

Hi all,

I found the solution for my scenario after i browse through the forum.

Here are the code that will serve my requirement:

    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender

 

 

        If RadGrid1.MasterTableView.RenderColumns.Length > 2 Then

 

 

 

 

        RadGrid1.MasterTableView.RenderColumns(2).Display =

False

 

 

 

 

        RadGrid1.MasterTableView.RenderColumns(5).Display =

False

 

 

 

 

 

    End If

Tags
Grid
Asked by
Lim
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Lim
Top achievements
Rank 1
Share this question
or