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

Hide and unhide columns not working with Display and Visible properties.

3 Answers 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 31 Aug 2011, 08:42 PM
Hi
I tried to hide and unhide columns with different option but nothing looks working with RadGrid.

1. I have a dropdown- checkbox with Column names,whose values I am storing in hashtable on button click.

protected void btnChooseColumns_Clicked(object sender, EventArgs e)
   {
       ht = new Hashtable();
       foreach (RadComboBoxItem item in rcColumnChooser.Items)
       {
           CheckBox checkBox = (CheckBox)item.FindControl("CheckBox");
           ht.Add(item.Text, checkBox.Checked);
       }
          BindGrid();
   }

Now after the BindGrid() method executed it is going to ColumnCreated event and executing as expected.

protected void rgCatalogs_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
    {
        if (ht != null)
        {
            if (ht.Contains(e.Column.HeaderText.ToUpper()))
            {
                GridBoundColumn boundColumn = e.Column as GridBoundColumn;
                e.Column.Visible = (bool)ht[e.Column.HeaderText];
            }
        }
         
    }

But column hide and unhide is not happening.

Thanks in Advance
RamC

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 05 Sep 2011, 09:15 AM
Hi Ram,

You should be able to set display or visible properties to the columns on ColumnCreated event. But please note that this event is fired only for the auto generated columns.
So if you want to hide a column that you have added (in the declaration of the grid or dynamically ) you should manually loop thought all columns in the grid. For example on grid's PreRender event:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadGrid grid = (sender as RadGrid);
 
    foreach (GridColumn column in grid.Columns)
    {
        column.Display = false;
    }
}
If you want to be able later to show these columns client side, use DIsplay="false". And if you don't want to render the columns use Visible="false".

All the best,
Vasil
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ram
Top achievements
Rank 1
answered on 08 Sep 2011, 10:12 PM
I am trying to use Radcombo Checkbox control with Filter capabilities and nothing happens. Please help urgent.

Code is below:
ASPX:
<telerik:RadComboBox ID="drpQualInitiative" runat="server" DataValueField="ProgramId"
                DataTextField="Name" HighlightTemplatedItems="true" AllowCustomText="true" Filter="Contains" EnableLoadOnDemand="true" ShowMoreResultsBox="false"
                EnableVirtualScrolling="true" EnableItemCaching="true"
                 
                OnClientDropDownClosed="onDropDownClosing">
                <HeaderTemplate>
                    <asp:CheckBox runat="server" ID="chkAll" Enabled="true" onclick="onchkStatusAllClick(this)" />
                    Select All
                </HeaderTemplate>
                 
                <Items>
                    <telerik:RadComboBoxItem runat="server" Text="Select/Deselect All" Value="" />
                </Items>
                <ItemTemplate>
                    <div onclick="StopPropagation(event)">
                        <asp:CheckBox runat="server" ID="qualityChkbox" onclick="onCheckBoxClick(this)" Text="" />
                        <%# Eval("Name") %>
                    </div>
                </ItemTemplate>
            </telerik:RadComboBox>
ASPX.CS:
 
drpQualInitiative.DataSource = GetPrograms();//Get prorams will return a list of Programs with ProgramId and Name columns
drpQualInitiative.DataBind();


Thanks In Advance,
Shrikkanth
0
Kalina
Telerik team
answered on 13 Sep 2011, 08:54 AM
Hello Ram,

Let me suggest you check the following Code-Library which implements the similar scenario.
Combobox with checkboxes and select all.

Kind regards,
Kalina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Ram
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Ram
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or