I have a RadGrid that has two columns that are invisible to begin with.
When I click a button outside the Grid I want the columns to become visible.
I know that there is a property in the grid (e.g. this.RadGrid1.Columns[0].Visible = true;), but the columns still won't show after setting them to visible in the button click event.
The interesting thing is that if I click the "Refresh" button within the Grid after having clicked the external button the columns show up.
I tried this.RadGrid1.Rebind(), but that doesn't do it either. It seems like only the "Refresh" in the Grid itself makes the columns visible.
How do I get the columns to become visible on the button click outside the grid?
This has got to be something fairly obvious, but I just don't see it.
Any help is appreciated.
When I click a button outside the Grid I want the columns to become visible.
I know that there is a property in the grid (e.g. this.RadGrid1.Columns[0].Visible = true;), but the columns still won't show after setting them to visible in the button click event.
The interesting thing is that if I click the "Refresh" button within the Grid after having clicked the external button the columns show up.
I tried this.RadGrid1.Rebind(), but that doesn't do it either. It seems like only the "Refresh" in the Grid itself makes the columns visible.
How do I get the columns to become visible on the button click outside the grid?
This has got to be something fairly obvious, but I just don't see it.
Any help is appreciated.
4 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Aug 2009, 05:54 AM
Hi Stephen,
You must explicitly call the Rebind() after setting the Visible property of the column to true. But I am not sure why it is not working on your end. Can you try accessing the columns using their UniqueName property rather than using the columnIndex. Here is the code snippet which i tried on my end.
CS:
One another suggestion will be to hide/show the column using the Display property instead of Visible property.
Thanks
Princy
You must explicitly call the Rebind() after setting the Visible property of the column to true. But I am not sure why it is not working on your end. Can you try accessing the columns using their UniqueName property rather than using the columnIndex. Here is the code snippet which i tried on my end.
CS:
| protected void Button1_Click(object sender, EventArgs e) |
| { |
| RadGrid1.MasterTableView.GetColumn("ProductName").Visible = true; |
| RadGrid1.MasterTableView.GetColumn("ProductID").Visible = true; |
| RadGrid1.Rebind(); |
| } |
One another suggestion will be to hide/show the column using the Display property instead of Visible property.
Thanks
Princy
0
Stephan
Top achievements
Rank 1
answered on 07 Aug 2009, 01:07 PM
Hi Princy,
Using the UniqueName property didn't work either, but using the Display property does the trick!
Now I can use either the UniqueName or the column index as long as I use the Display property.
Thanks a million. This was starting to drive me crazy.
Below are both scenarios I described above that work:
or
Using the UniqueName property didn't work either, but using the Display property does the trick!
Now I can use either the UniqueName or the column index as long as I use the Display property.
Thanks a million. This was starting to drive me crazy.
Below are both scenarios I described above that work:
| protected void Button1_Click(object sender, EventArgs e) |
| { |
| RadGrid1.MasterTableView.GetColumn("ProductName").Display = true; |
| RadGrid1.MasterTableView.GetColumn("ProductID").Display = true; |
| RadGrid1.Rebind(); |
| } |
| protected void Button1_Click(object sender, EventArgs e) |
| { |
| RadGrid1.Column[0].Display = true; |
| RadGrid1.Column[1].Display = true; |
| RadGrid1.Rebind(); |
| } |
0
Princy
Top achievements
Rank 2
answered on 10 Aug 2009, 07:07 AM
Hi Stephan
Let me also share some additional information of what i understood regarding the Visible/Display property:
Display property indicates whether the cells corresponding to a column should be rendered with a 'display:none' style attribute. Display property is useful if you want to hide/show columns client-side without post-back/Ajax request. Visible property is useful if you do not want to show a column or completely prevent cells from rendering, server-side. When the Visible property of the RadGrid control is set to False, the NeedDataSource event does not fire. (This has been done to optimize performance). When you change the Visible property of the grid to True, you must call the grid's Rebind method so that it can bind to its data.
Visible/Invisible conventions
Best Regards
Princy.
Let me also share some additional information of what i understood regarding the Visible/Display property:
Display property indicates whether the cells corresponding to a column should be rendered with a 'display:none' style attribute. Display property is useful if you want to hide/show columns client-side without post-back/Ajax request. Visible property is useful if you do not want to show a column or completely prevent cells from rendering, server-side. When the Visible property of the RadGrid control is set to False, the NeedDataSource event does not fire. (This has been done to optimize performance). When you change the Visible property of the grid to True, you must call the grid's Rebind method so that it can bind to its data.
Visible/Invisible conventions
Best Regards
Princy.
0
Stephan
Top achievements
Rank 1
answered on 10 Aug 2009, 02:45 PM
Princy,
I don't know why it never occurred to me to use the Display property, but my understanding on how the Visible property works was spot on to your explanation.
The thing that just baffled me and threw me for a loop was the Rebind still wasn't showing the columns that I made visible.
It has probably something to do with how I use the Ajax updatepanel, but I still don't really understand what I did wrong.
Anyway, thanks for your input and using the Display property makes more sense in my case anyway.
I don't know why it never occurred to me to use the Display property, but my understanding on how the Visible property works was spot on to your explanation.
The thing that just baffled me and threw me for a loop was the Rebind still wasn't showing the columns that I made visible.
It has probably something to do with how I use the Ajax updatepanel, but I still don't really understand what I did wrong.
Anyway, thanks for your input and using the Display property makes more sense in my case anyway.