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

Can't toggle column visibility

5 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Williams
Top achievements
Rank 1
Mark Williams asked on 24 Apr 2010, 07:50 PM
I am trying something very basic, namely to toggle the visibility of a column based on a selection from a dropdown. My simple test code is below. The problem I have is that making the column disappear (when the WEBVALIDATION dropdown value is selected) works fine and the colMainName does disappear. However, when I select the DEFAULT dropdown value the column does not re-appear. I stepped through this and the line where I set the visibility to true is called. Any thoughts?

 

if (e.Value.ToUpper() == "DEFAULT")

 

{

gv.MasterTableView.GetColumn(

"colMainName").Visible = true;

 

}

 

if (e.Value.ToUpper() == "WEBVALIDATION")

 

{

gv.MasterTableView.GetColumn(

"colMainName").Visible = false;

 

}

Thanks.

Mark

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Apr 2010, 09:06 AM
Hello Mark,

You can either set Display property in order show/hide the column or set the Visible property and rebind the grid after setting Visible property. Checkout the examples.


Option 1: By setting the Display property.
CS:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList dr = (DropDownList)sender; 
        if (dr.SelectedValue == "DEFAULT"
        { 
            RadGrid1.MasterTableView.GetColumn("colMainName").Display = true
        } 
        if (dr.SelectedValue == "WEBVALIDATION"
        { 
            RadGrid1.MasterTableView.GetColumn("colMainName").Display = false
        } 

Option 2: By setting the Visibe property.
CS:   
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        DropDownList dr = (DropDownList)sender; 
        if (dr.SelectedValue == "DEFAULT"
        { 
            RadGrid1.MasterTableView.GetColumn("colMainName").Visible = true
        } 
        if (dr.SelectedValue == "WEBVALIDATION"
        { 
            RadGrid1.MasterTableView.GetColumn("colMainName").Visible = false
        } 
        RadGrid1.Rebind(); 
         
    } 

Regards,
Shinu.
0
Mark Williams
Top achievements
Rank 1
answered on 26 Apr 2010, 06:45 PM
Thanks for the response, Shinu. So, I believe I may have got a little confused with the documentation about whether this is client-side or server-side logic. For future reference, can you clarify to me how the visibility of the columns is controlled for both Visible and Display (client or server-side)?

Thanks again.

Mark
0
Dimo
Telerik team
answered on 28 Apr 2010, 09:13 AM
Hello Mark,

The Visible property determines whether the column will be rendered on the client. If you set Visible="false", the column will not exist on the client and you will not be able to show it with the client API. The Display property determines whether the column will be displayed on the client. Setting Display="false" does not prevent the column from being rendered and it exists on the client.

Regards,
Dimo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mark Williams
Top achievements
Rank 1
answered on 28 Apr 2010, 04:19 PM
Thank you, Dimo. So, one final question in terms of the best pattern to follow here. The scenario I have is a reasonably common one, I would think. I have a RadGrid that is used for various purposes. For example, in "vendor management mode" I might present a list of common columns such as name, contact, eMail, etc. In "site validation" mode I have a different set of columns (name, URL, web site status, etc). I want to offer a dropdown menu that lets the user switch between these modes and have the column set change accordingly. With that in mind, what would you consider to be the best way to approach this - through the Visible or Display properties?

Finally, can you confirm that when I use Visible to add or remove columns I would always need to rebind?

Thanks.

Mark
0
Dimo
Telerik team
answered on 29 Apr 2010, 12:51 PM
Hello Mark,

As far as I can see, you are switching the modes server-side. In this case it is better to use the Visible property, so that no unnecessary columns are rendered and the HTML output is smaller.

And yes, you need to rebind.

Greetings,
Dimo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Mark Williams
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark Williams
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or