Hiding Column at Runtime

7 posts, 1 answers
  1. DK
    DK avatar
    72 posts
    Member since:
    Jun 2009

    Posted 03 Dec 2009 Link to this post

    Hi i am using radgrid.
    I have two questions regarding this.

    I have different dataset and single grid.
    so I have not defined columns in the grid.
    Columns are generated through the dataset columns.

    1. Now i want to hide the first column of the grid.
    2. I want to add a column for deleting the record.

    How can i do this?
    Please suggest me some idea...
  2. DK
    DK avatar
    72 posts
    Member since:
    Jun 2009

    Posted 03 Dec 2009 Link to this post

    i ma trying the following code but it is not able to hide the column.
    both of the following codes are not working for me

    Private void RadGrid1_PreRender(Object sender,EventArgs e) 
    {  
        If (RadGrid1.MasterTableView.RenderColumns.Length > 2) 
            RadGrid1.MasterTableView.RenderColumns[2].Display = False  
            RadGrid1.MasterTableView.RenderColumns[3].Display = False  
         
     
     
    and also tried 
     
     
    Private void RadGrid1_PreRender(Object sender,EventArgs e) 
    {  
        If (RadGrid1.MasterTableView.RenderColumns.Length > 2) 
            RadGrid1.MasterTableView.RenderColumns[2].visible= False  
            RadGrid1.MasterTableView.RenderColumns[3].visible= False  
         

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 03 Dec 2009 Link to this post

    Hi DK,

    I assume you want to hide AutoGeneratedColumn from code behind. If so please try the following code snippet:
    C#:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (RadGrid1.MasterTableView.RenderColumns.Length > 2) {
            RadGrid1.MasterTableView.RenderColumns(2).Display = false;
        }
    }

    About your second question, please refer to these articles, for more information about how to achieve your goal.
    Deleting records
    Automatic operations

    I hope this helps.

    Kind regards,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. DK
    DK avatar
    72 posts
    Member since:
    Jun 2009

    Posted 03 Dec 2009 Link to this post

    you code

    RadGrid1.MasterTableView.RenderColumns(2).Display = false;

    giving error
    Telerik.Web.UI.GridTableView.RenderColumns can not be used like a method..
    now plz help me what to do now?

    and also the links you provided is not as helpful as i want
  6. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Dec 2009 Link to this post

    Hi DK,

    Try replacing the above code as shown below and see if it helps:
    c#:
    RadGrid1.MasterTableView.RenderColumns[2].Display = false

    You can also use the following code to hide a column using the UniqueName of the column which is the same as the Datafield name of the column:
    RadGrid1.MasterTableView.GetColumn("ColumnDataFieldName").Display = false;

    Thanks
    Princy.
  7. swagatika
    swagatika avatar
    3 posts
    Member since:
    Sep 2011

    Posted 25 Nov 2014 in reply to Princy Link to this post

    WBSRadGrid.MasterTableView.GetColumn("ActualEndDate").Visible = false;
    //or
                WBSRadGrid.MasterTableView.Columns.FindByUniqueName("ActualEndDate").Visible 

    = false;

  8. swagatika
    swagatika avatar
    3 posts
    Member since:
    Sep 2011

    Posted 25 Nov 2014 in reply to DK Link to this post

    WBSRadGrid.MasterTableView.GetColumn("ActualEndDate").Visible = false;
    //or
                WBSRadGrid.MasterTableView.Columns.FindByUniqueName("ActualEndDate").Visible 

    = false;

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017