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

How do I hide a row from view in a radgrid

7 Answers 2060 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 23 Jul 2010, 06:26 PM
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.

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jul 2010, 05:47 AM
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.
0
gc_0620
Top achievements
Rank 1
answered on 17 Aug 2010, 04:43 AM
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

0
gc_0620
Top achievements
Rank 1
answered on 17 Aug 2010, 05:18 AM

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
               }
           }
0
Princy
Top achievements
Rank 2
answered on 17 Aug 2010, 05:19 AM
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.
0
Anna Katrina
Top achievements
Rank 1
answered on 01 Jul 2013, 06:37 AM
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..
0
Maria Ilieva
Telerik team
answered on 03 Jul 2013, 11:27 AM
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.
0
Tuan
Top achievements
Rank 1
answered on 28 Jul 2017, 04:37 PM

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;

}
}

 


 

Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Anna Katrina
Top achievements
Rank 1
Maria Ilieva
Telerik team
Tuan
Top achievements
Rank 1
Share this question
or