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

Deleting a row in itemdatabound

5 Answers 90 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gijo
Top achievements
Rank 1
Gijo asked on 18 Feb 2009, 10:25 PM

I want to delete certains rows based on a condition while binding the grid. I am using the below code. But 'item.Visible = false;'
is not working while 'item.Enabled = false;' is working.  Any idea?


protected void userGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
                GridDataItem item = (GridDataItem)e.Item;
                if (item["UserName"].Text.ToString() == "SuperAdmin")
                {
                                     item .Visible = false;
                                    // item.Enabled = false;
               }

   }
}

5 Answers, 1 is accepted

Sort by
0
Gijo
Top achievements
Rank 1
answered on 18 Feb 2009, 11:03 PM
I solved this.
I used 'item.Display = false;' instead of 'item.Visible= false;' and it did the trick.
But another issue props up. The <AlternatingItemStyle> and <ItemStyle> mess up. If you look at the grid you can see <ItemStyle> applied to consecutive  rows and so as <AlternatingItemStyle>. 
0
MBEN
Top achievements
Rank 1
Veteran
answered on 15 Jul 2015, 11:16 PM

I have a similar issue.

If I hide the item, then it messes with the row color scheme.

Can I hide the item and still have the alternating row colors?

0
Eyup
Telerik team
answered on 20 Jul 2015, 08:34 AM
Hello,

You can achieve this requirement using the following approach:
Copy Code
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        item.CssClass = item.ItemIndex % 3 == 0 ? "rgAltRow" : "rgRow";
    }
}

Hope this helps.

You can also examine the sample provided in the following code-library for a client-side approach:
http://www.telerik.com/support/code-library/quick-search---filtering-rows-depending-on-entered-text-instantly-when-paging-is-disabled#7QZA0lkbHkuCwOZn23V7Hg


Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
MBEN
Top achievements
Rank 1
Veteran
answered on 20 Jul 2015, 04:25 PM

Unfortunately that does not help. I still get two consecutive rows with the same color.

Since the assignment of row color is based on ItemIndex, it still messes with the color.

Any other ideas?

0
Eyup
Telerik team
answered on 23 Jul 2015, 10:15 AM
Hi,

Please try using the following approach and let me know about the result:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        if (item.ItemIndex % 3 == 0)
        {
            item.Display = false;
        }
    }
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    GridDataItem[] visibleItems = RadGrid1.Items.OfType<GridDataItem>().Where(x => x.Display).ToArray();
    for (int i = 0; i < visibleItems.Length; i++)
    {
        visibleItems[i].CssClass = i % 2 == 0 ? "rgRow" : "rgAltRow";
    }
}

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Gijo
Top achievements
Rank 1
Answers by
Gijo
Top achievements
Rank 1
MBEN
Top achievements
Rank 1
Veteran
Eyup
Telerik team
Share this question
or