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

How to hide Form Fields in Add mode

2 Answers 234 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kasi
Top achievements
Rank 1
kasi asked on 13 Jun 2011, 01:11 PM
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 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Jun 2011, 07:31 PM
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
0
Aarsh
Top achievements
Rank 1
answered on 18 Apr 2013, 03:44 PM
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
Tags
Grid
Asked by
kasi
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Aarsh
Top achievements
Rank 1
Share this question
or