how to hide columns in radgrid

4 posts, 1 answers
  1. Babu Puchakayala
    Babu Puchakayala avatar
    79 posts
    Member since:
    May 2010

    Posted 09 Jun 2010 Link to this post

    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

  2. Babu Puchakayala
    Babu Puchakayala avatar
    79 posts
    Member since:
    May 2010

    Posted 09 Jun 2010 Link to this post

    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

  3. Answer
    Shinu
    Shinu avatar
    17595 posts
    Member since:
    Mar 2007

    Posted 10 Jun 2010 Link to this post

    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.

  4. Babu Puchakayala
    Babu Puchakayala avatar
    79 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    Hi Shinu,

    That works great. Thanks fro your help.

Back to Top