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

How to hide controls in edit form template on edit, and show them on insert?

1 Answer 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 10 Dec 2008, 08:40 PM
Is it possible to hide controls in edit form template when a user selects edit, and then show the same controls when the user hits add new record?

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Dec 2008, 04:02 AM
Hi Aaron,

You can try the following code snippet to achieve the desired scenario.

ASPX:
 <EditFormSettings EditFormType="Template" > 
                 <FormTemplate> 
                   <asp:Label ID="Label1" runat="server" Text="NewRecord"></asp:Label> 
                     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
                 </FormTemplate> 
            </EditFormSettings> 

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        //to hide the label in edit from
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)&&(!e.Item.OwnerTableView.IsItemInserted)) 
        { 
            GridEditFormItem edititem = (GridEditFormItem)e.Item; 
            Label lbl = (Label)edititem.FindControl("Label1"); 
            lbl.Visible = false
        } 
        //to show the label in insert form
        else if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted)&&(!e.Item.IsInEditMode)) 
        { 
            GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item; 
            Label lbl = (Label)insertitem.FindControl("Label1"); 
            lbl.Visible = true
        } 
  }  


Shinu.
Tags
Grid
Asked by
Aaron
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or