how to hide columns in radgrid

1 Answer 2491 Views
Grid
Babu Puchakayala
Top achievements
Rank 1
Babu Puchakayala asked on 10 Jun 2010, 03:45 AM
Hi,

I have rad grid. I want to hide the columns in a radgrid. How to hide it. This is my rad grid
<telerik:RadGrid ID="gvCktMap" AllowFilteringByColumn="True" OnNeedDataSource="gvCktMap_NeedDataSource" 
        AllowSorting="True" PageSize="15" AllowPaging="True" runat="server" GridLines="None" 
        ShowGroupPanel="True" EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" 
        EnableViewState="false" OnItemCreated="gvCktMap_ItemCreated"
        <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True"
            <ClientEvents OnRowDblClick="RowDblClick" /> 
            <Scrolling AllowScroll="true" UseStaticHeaders="true" /> 
            <Selecting AllowRowSelect="True"></Selecting> 
            <Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True" 
                ResizeGridOnColumnResize="False"></Resizing> 
        </ClientSettings> 
        <GroupingSettings ShowUnGroupButton="true" /> 
        <PagerStyle Mode="NextPrevAndNumeric" HorizontalAlign="Right" Font-Bold="true" /> 
    </telerik:RadGrid> 

and this my codebehind.
    protected void Page_Load(object sender, EventArgs e) 
    { 
        try 
        { 
            winPopUps.InitiallyShown = false
            winFilter.InitiallyShown = false
            Response.AddHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 5)); 
            if (Session.IsNewSession) 
            { 
                Response.Redirect("Default.aspx"); 
            } 
            if (!IsPostBack) 
            { 
                if (Session["TaskName"] != null) 
                    lblTaskName.Text = Session["TaskName"].ToString(); 
                Session["FilColms"] = null; 
                Session["SortExp"] = null; 
                Session["FilExp"] = null; 
                Session["ViewAll"] = null; 
                if (Session["TaskID"].ToString() == "206" || Session["TaskID"].ToString() == "209" || Session["TaskID"].ToString() == "208" || Session["TaskID"].ToString() == "207" || Session["TaskID"].ToString() == "210" || Session["TaskID"].ToString() == "400" || Session["TaskID"].ToString() == "401" || Session["TaskID"].ToString() == "402" || Session["TaskID"].ToString() == "403" || Session["TaskID"].ToString() == "404" || Session["TaskID"].ToString() == "216" || Session["TaskID"].ToString() == "215") 
                { 
                    lnkbtnComplete.Visible = false
                    if (Session["TaskID"].ToString() == "208") 
                    { 
                        lblBlkLbl1.Text = "Req SM Imp Date :"
                        lblBlkLbl2.Text = "CM Number :"
                        trBulkUpdates.Width = "63%"
                    } 
                    else if (Session["TaskID"].ToString() == "209") 
                    { 
                        lblBlkLbl1.Text = "Foc Date :"
                        lblBlkLbl2.Text = "Actual PTD :"
                        trBulkUpdates.Width = "67%"
                        txtBlkTxt3.Visible = true
                        lblBlkLbl3.Visible = true
                        lblBlkLbl3.Text = "Notificaiton Date :"
                        txtPackageSlip.Width = 100
                        valextFOCDt.Enabled = true
                        clnderFOCDt.Enabled = true
                        valFOCDt.Enabled = true
                    } 
                    else if (Session["TaskID"].ToString() == "215") 
                    { 
                        lblBlkLbl1.Text = "Gate3 Date :"
                        lblBlkLbl2.Text = "Gate2 Date :"
                        trBulkUpdates.Width = "73%"
                        txtBlkTxt3.Visible = true
                        lblBlkLbl3.Visible = true
                        lblBlkLbl3.Text = "Customer Accepted Date :"
                        txtPackageSlip.Width = 100
                        valextFOCDt.Enabled = true
                        clnderFOCDt.Enabled = true
                        valFOCDt.Enabled = true
                    } 
                    else if (Session["TaskID"].ToString() == "207") 
                    { 
                        lblBlkLbl1.Text = "CPE Ship Date :"
                        lblBlkLbl2.Text = "Package Slip :"
                        trBulkUpdates.Width = "58%"
                    } 
                    else if (Session["TaskID"].ToString() == "210" || Session["TaskID"].ToString() == "402") 
                    { 
                        lblBlkLbl1.Text = "Sch SM Imp Date :"
                        lblBlkLbl2.Text = "SM Number"
                        trBulkUpdates.Width = "63%"
                    } 
                    else if (Session["TaskID"].ToString() == "400") 
                    { 
                        lblBlkLbl1.Text = "PO Number :"
                        lblBlkLbl2.Text = "Req Number :"
                        ClndrPhyDt.Enabled = false
                        valPhyDt.Enabled = false
                        valCanlnder.Enabled = false
                        trBulkUpdates.Width = "60%"
                    } 
                    else if (Session["TaskID"].ToString() == "401") 
                    { 
                        lblBlkLbl1.Text = "NOC Acceptance Package Completion Date :"
                        lblBlkLbl2.Text = string.Empty; 
                        lblBlkLbl2.Visible = false
                        txtPackageSlip.Text = string.Empty; 
                        txtPackageSlip.Visible = false
                        trBulkUpdates.Width = "55%"
                    } 
                    else if (Session["TaskID"].ToString() == "403") 
                    { 
                        lblBlkLbl1.Text = "NOC Acceptance Date :"
                        lblBlkLbl2.Text = string.Empty; 
                        lblBlkLbl2.Visible = false
                        txtPackageSlip.Text = string.Empty; 
                        txtPackageSlip.Visible = false
                        trBulkUpdates.Width = "43%"
                    } 
                    else if (Session["TaskID"].ToString() == "404" || Session["TaskID"].ToString() == "216") 
                    { 
                        lblBlkLbl1.Text = "Billing Start Date :"
                        lblBlkLbl2.Text = "Saville Account Number :"
                        trBulkUpdates.Width = "70%"
                    } 
                    else if (Session["TaskID"].ToString() == "206") 
                    { 
                        lblBlkLbl1.Text = "Config Gen Date :"
                        lblBlkLbl2.Text = string.Empty; 
                        lblBlkLbl2.Visible = false
                        txtPackageSlip.Text = string.Empty; 
                        txtPackageSlip.Visible = false
                        trBulkUpdates.Width = "40%"
                    } 
                } 
            } 
            bingGrid(); 
 
        } 
        catch (Exception ex) 
        { 
        } 
    } 
 
 
 
 
    private void bingGrid() 
    { 
        try 
        { 
            gvCktMap.Columns.Clear(); 
            DataSet dsResult = new DataSet(); 
            DataSet dsEditItems = new DataSet(); 
            dsEditItems.ReadXml(Server.MapPath("XMLS/" + Session["TaskID"].ToString() + ".xml")); 
 
            clsSearch_BL clsObj = new clsSearch_BL(); 
            clsObj.TaskID = (string)Session["TaskID"]; 
            clsObj.CustName = (string)Session["CustName"]; 
            clsObj.MarketName = (string)Session["MarketName"]; 
            clsObj.HeadendName = (string)Session["HeadendName"]; 
            clsObj.SiteName = (string)Session["SiteName"]; 
            clsObj.TaskStatus = (string)Session["TaskStatus"]; 
            clsObj.OrdType = (string)Session["OrdType"]; 
            clsObj.OrdStatus = (string)Session["OrdStatus"]; 
            clsObj.ProName = (string)Session["ProName"]; 
            clsObj.LOC = (string)Session["LOC"]; 
 
            dsResult = clsObj.getSearchResults_BL(clsObj); 
            Session["SearchRes"] = dsResult; 
            DataTable dtFilter = new DataTable(); 
            DataColumn dtCol = new DataColumn("FilterBy"); 
            dtFilter.Columns.Add(dtCol); 
            dtCol = new DataColumn("DataType"); 
            dtFilter.Columns.Add(dtCol); 
            gvCktMap.DataSource = dsResult
 
 
    protected void gvCktMap_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
    { 
        bingGrid(); 
    } 


i want to hide sid, customername and marketname columns before it displays to the user. I dont have any idea how to do that. Please help me.

Thanks
Babu Puchakayala
Top achievements
Rank 1
commented on 10 Jun 2010, 04:17 AM

i want to hide columns before it displays to the user. SO i cant use headercontext menu option. Please let me know.

Thanks In Advance

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 10 Jun 2010, 07:19 AM
Hello Babu,

You can try the following code snippet in PreRender event to hide the columns and then Rebind the grid.

C#:
 
 protected void gvCktMap_PreRender(object sender, EventArgs e) 
    { 
        gvCktMap.MasterTableView.GetColumn("sid").Visible = false;  
        gvCktMap.MasterTableView.GetColumn("customername").Visible = false
        gvCktMap.MasterTableView.GetColumn("marketname").Visible = false
        gvCktMap.Rebind(); 
    } 

Regards,
Shinu.
Babu Puchakayala
Top achievements
Rank 1
commented on 10 Jun 2010, 03:02 PM

Hi Shinu,

That works great. Thanks fro your help.
Keith
Top achievements
Rank 1
commented on 15 Nov 2019, 10:20 PM

Hi there.  The code seems to work for Babu but I cannot get my code to fire.  When I add a breakpoint the following code is not executed.

public partial class Default : System.Web.UI.Page
{
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        RadGrid1.MasterTableView.GetColumn("GrandPrix").Visible = false;
        RadGrid1.Rebind();
    }
}

 

Eyup
Telerik team
commented on 20 Nov 2019, 08:24 AM

Hello Keith,

 

You can ensure that the event is attached in the mark-up, too:

        <telerik:RadGrid ID="RadGrid1" ... OnPreRender="RadGrid1_PreRender">
And then you can set the Visible or Display property of the column to false. Generally, calling the Rebind() method is not required in this case.

I hope this will prove helpful. Let me know if I can assist with anything else.

 

Regards,
Eyup
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Babu Puchakayala
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or