How do I hide a row from view in a radgrid

8 posts, 0 answers
  1. Richard
    Richard avatar
    26 posts
    Member since:
    Oct 2008

    Posted 23 Jul 2010 Link to this post

    I have a radGrid that has several rows.  One of the rows is a row that cannot be deleted by the user.  I would like to hide the row from view.  What event would I use to hide the row and what is the code to hide the row.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Jul 2010 Link to this post

    Hello Richard,

    In order to achieve this try the following code snippet in ItemDataBound event.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               if (item.GetDataKeyValue("EmployeeID").ToString() == "4"//set your condition for hiding the row
               {
                   item.Display = false//hide the row
               }
           }
       }

    Thanks,
    Princy.
  3. gc_0620
    gc_0620 avatar
    246 posts
    Member since:
    Feb 2008

    Posted 16 Aug 2010 Link to this post

    Princy,

    Hi there. How do you hide the rows by setting conditions to a non-data key value columns? For example if I set condition to data key value "CustomerID", it works but If I set data key value to "CompanyName", I can't hide the row.  I would like to hide the row based on the value of "CompanyName" instead of "CustomerId". 

     

    This works:

     

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

     

    {

     

     

        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Master")

     

            {

     

                GridDataItem item = (GridDataItem)e.Item;

     

     

                if (item.GetDataKeyValue("CustomerID").ToString().Substring(0, 1) == "A")

     

     

                {

                item.Display =

    false; //hide the row

     

                }

            }

        }

    This does not work..

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

     

    {

     

     

        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Master")

     

            {

     

                GridDataItem item = (GridDataItem)e.Item;

     

     

                if (item.GetDataKeyValue("CompanyName").ToString().Substring(0, 1) == "A")

     

     

                {

                item.Display =

    false; //hide the row

     

     

     

     

     

                }

            }

        }

     


    Thanks

    GC_0620

  4. gc_0620
    gc_0620 avatar
    246 posts
    Member since:
    Feb 2008

    Posted 17 Aug 2010 Link to this post

    Please disregard my earlier thread. It is solved. Correct syntex should be below  because CompanyName is not a GetDataKeyValue.

    Thanks Princy and others.

    GC_0620

    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Master")
               {
                   GridDataItem item = (GridDataItem)e.Item;
                   if (item["CompanyName"].Text.ToString().Substring(0, 1) == "A")
                      
                   {
                       item.Display = false;  //hide the row
                   }
               }
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 17 Aug 2010 Link to this post

    Hello,

    One option is you can access the cell value by using ColumnUniqueName'. Please refer the following documentation
    Accessing cells and rows

    Another option to get the data for the column 'CompanyName' is by adding the field name to the DataKeyNames property.

    ASPX:
    <MasterTableView  DataKeyNames="CompanyName" . . .  >

    Thanks,
    Princy.
  6. Anna Katrina
    Anna Katrina avatar
    9 posts
    Member since:
    Feb 2013

    Posted 01 Jul 2013 Link to this post

    Hello guys,

    I am doing my program in silverlight 5. Unfortunately, i cant seem to find the namespace GridItemEventArgs, or ItemDataBound event, or event the GridDataItem.
    I'm currently using Telerik.Windows.Controls.GridView.RowLoadedEventArgs e, however, when i used 

    e.Row.Visibility = System.Windows.Visibility.Collapsed;

    the row is not visible but it leaves a row of blank space.How can i hide it without leaving the white blank space?
    Thanks..
  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 03 Jul 2013 Link to this post

    Hello Anna,

    The mentioned namespace and events are available only for the RadGrid control for ASP .NET Ajax. Note that in case you have any issues with the RadGridView control for Winforms you should post you question in the Winforms forums.

    Regards,
    Maria Ilieva
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  8. Tuan
    Tuan avatar
    1 posts
    Member since:
    Jan 2007

    Posted 28 Jul 2017 in reply to Princy Link to this post

    Hi Princy,

    I've tried everything but cannot get my row to hide. The database table is named Archived and I want to be able to hide it from view if it is Archived. Please see code below. Thank you.

     

     

    public partial class ProjectGridView : System.Web.UI.UserControl
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    if (!IsPostBack)
    bindParentData();

    }

    private void bindParentData()
    {
    rgResults.DataSource = Status.GetStatesByType(StatusType.Project);
    rgResults.DataBind();
    }

            //public void BindData(int id)
            //{

            //}
    protected void rgResults_ItemDataBound(object sender, GridItemEventArgs e)
    {
                //throw new NotImplementedException();

              

                if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == ""))
    {
    var item = (GridDataItem)e.Item; 
    var lbl = (Label)item.FindControl("lblStatus");
    var szStatus = item.GetDataKeyValue("Value").ToString();
    var status = (StatusValue)Enum.Parse(typeof(StatusValue), szStatus);
    var cnt = Project.GetProjectsByUser(Page.User.Identity.Name, null, status, (string.IsNullOrEmpty(txtProjectFilter.Text) ? null : txtProjectFilter.Text) ).Count;

    lbl.Text = szStatus + " (" + cnt.ToString() + ")";
    }

    if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "ctrlProject")) 

    GridDataItem item = (GridDataItem)e.Item; 
    var hf = (ProjectStatusControl)item["Proj"].FindControl("ctrlProjectStatus");
                  
                    hf.BindData(Convert.ToInt32(item.OwnerTableView.ParentItem.GetDataKeyValue("ProjectID").ToString()));
                   
                }
                if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "ctrlProject"))

                {
                    GridEditableItem item = (GridEditableItem)e.Item;
                 //   GridDataItem item = (GridDataItem)e.Item;
                    //var archive = (ProjectStatusControl)item["Proj"].FindControl("ctrlProjectStatus");
                    //archive.BindData(Convert.ToInt32(item.OwnerTableView.ParentItem.GetDataKeyValue("Archive").ToString()));
                    if (item["Archive"].FindControl("ctrlProjectStatus").ToString() == "1") //set your condition for hiding the row
                    {
                       
                        item.Display = false;  //hide the row

                    }
                }

                if ((e.Item is GridDataItem) && (e.Item.OwnerTableView.Name == "ctrlTable"))
    {
    GridDataItem item = (GridDataItem)e.Item;
    Project prj = item.DataItem as Project;

                  
                    var hlSRF = (HyperLink)item.FindControl("hlSRF");
    hlSRF.NavigateUrl = "~/ServiceRequest.aspx?pid=" + item.GetDataKeyValue("ProjectID").ToString();
    hlSRF.Text = string.IsNullOrEmpty(prj.Title) ? "No Title Specified" : prj.Title;

    var lbl = (Label)item.FindControl("lblSafetyOfficerApprovedDate");
    var approvedDate = prj.SafetyOfficerApprovedDate;
    if (prj.SampleData != null && prj.SampleData.IncludesRadMaterial)
    lbl.Text = approvedDate == null ? "Pending" : String.Format("{0:d}", approvedDate);
    else
    lbl.Text = @"N/A";

    lbl = (Label)item.FindControl("lblLabLeadApproval");
    approvedDate = prj.LabLeadApprovedDate;
    lbl.Text = approvedDate == null ? "Pending" : String.Format("{0:d}", approvedDate);
                   
                }
               


            }

            protected void rgResults_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    var dr = e.Row.DataItem as DataRowView;

                    if ((dr["Archived"]).ToString() == "1")
                        e.Row.Enabled = false;

                }
            }

            protected void rgResults_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
    //throw new NotImplementedException();
    GridDataItem item = e.DetailTableView.ParentItem;

    switch (e.DetailTableView.Name)
    {
    case "ctrlTable":
    var status = (StatusValue)Enum.Parse(typeof(StatusValue),item.GetDataKeyValue("Value").ToString());
                        var parentNodes = Project.GetProjectsByUser(Page.User.Identity.Name, null, status, (string.IsNullOrEmpty(txtProjectFilter.Text) ? null : txtProjectFilter.Text));
    if (!string.IsNullOrEmpty(txtProjectFilter.Text))
    parentNodes = parentNodes.Where(x => x.Title.ToLower().Contains(txtProjectFilter.Text.ToLower())).ToList();

    e.DetailTableView.DataSource = parentNodes;
    break;

    case "ctrlProject":
    var dtFool = new DataTable();
    dtFool.Columns.Add("Fool");
    dtFool.Rows.Add("");

    e.DetailTableView.DataSource = dtFool;
    break;

    }
    }

     


     

Back to Top