How to hide Form Fields in Add mode

3 posts, 0 answers
  1. kasi
    kasi avatar
    29 posts
    Member since:
    May 2011

    Posted 13 Jun 2011 Link to this post

    Hi ,
    I am facing one issue in rad grid. which is i have one grid while in edit mode i want to update all fields and if add mode i will have one drop down base on that i ll insert record for the grid. I want to hide the some of fields in add mode and display all in edit mode.
    Can any one give me solutions.
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 13 Jun 2011 Link to this post

    Hi,

    protected void rdgrid_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
            //if the item is about to edit
           {
               GridEditFormItem insertItem = (GridEditFormItem)e.Item;
                
           }
           if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
           //if the item is about to insert
           {
               GridEditFormInsertItem insertItem=(GridEditFormInsertItem)e.Item;
               // for example - hide dropdown
               DropDown dd1 = (DropDown)insertItem.FindControl("ddl");
               dd1.Visible = false
           }
       }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 18 Apr 2013 Link to this post

    That worked for me, I am also sharing my code snippet that demonstrates how can we do so on column-name basis

    for : Edit mode OR Insert Mode

    protected void BookPageAssignmentGrid_ItemDataBound(object sender, GridItemEventArgs e)
     {
        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode || e.Item.OwnerTableView.IsItemInserted))
        {
            GridEditFormItem item = (GridEditFormItem)e.Item;
            item[_key].Parent.Visible = false;
            item[_counts].Parent.Visible = false;
        }
    }

    I wanted to hide that column on read mode too, so that I added follwoing to this event handler ;

    protected void MailMergeSetup_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    try
                    {
                        if (item["_key"] != null)
                            item["_key"].Visible = false;
                    }
                    catch { }
                }

    and parallelly, I will also have to use GridHeaderItem in order to hide column header and also the extra row that we get b/w header adn data-rows where the filter sits can be hidden using  GridFilteringItem.

    Thanks,
    -Aarsh
Back to Top