Deleting a row in itemdatabound

6 posts, 0 answers
  1. Gijo
    Gijo avatar
    26 posts
    Member since:
    Jan 2008

    Posted 18 Feb 2009 Link to this post

    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;
                   }

       }
    }

  2. Gijo
    Gijo avatar
    26 posts
    Member since:
    Jan 2008

    Posted 18 Feb 2009 Link to this post

    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>. 
  3. MBEN
    MBEN avatar
    203 posts
    Member since:
    Nov 2011

    Posted 15 Jul 2015 Link to this post

    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?

  4. Eyup
    Admin
    Eyup avatar
    3756 posts

    Posted 20 Jul 2015 Link to this post

    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
  5. MBEN
    MBEN avatar
    203 posts
    Member since:
    Nov 2011

    Posted 20 Jul 2015 in reply to Eyup Link to this post

    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?

  6. Eyup
    Admin
    Eyup avatar
    3756 posts

    Posted 23 Jul 2015 Link to this post

    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
Back to Top