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

[Solved] hierarchical radgrid with user control edit forms

1 Answer 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Charles Hayes
Top achievements
Rank 1
Charles Hayes asked on 05 Nov 2009, 04:44 PM
We have a hierarchical radgrid with a mastertable and a single detail table.  We need edit/insert functionality on both levels, however, on the second (inner) level, we need to have a different user control for the insert than we need for the edit.  There is a field that we do not want editable but we need input for the insert.

How do I assign a different user control based on whether the user is inserting or editing a record on the inner table?  Is there some way within the user control to know if you are editing or inserting?  if so, I can use the same user control and hide the input control for edits.

I hope this makes sense, I am new to Rad controls.  I appreciate any help.

Thanks
Chuck

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Nov 2009, 08:05 AM
Hello Charles,

You can try out the following code to hide a control when in Edit mode but display it in insert mode:
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" runat="server" OnItemDataBound="RadGrid1_ItemDataBound"
      <MasterTableView Name="Master" DataSourceID="SqlDataSource1"
             <DetailTables> 
                     <telerik:GridTableView Name="Detail" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" 
                            runat="server"
                            .... 

c#:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.OwnerTableView.Name == "Detail" && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormItem item = (GridEditFormItem)e.Item;             
            UserControl user = (UserControl)item.FindControl(GridEditFormItem.EditFormUserControlID); 
            ((TextBox)user.FindControl("TextBox1")).Visible = false
        } 
    } 

and if you want to switch the user controls for Edit and Insert modes of the grid, you can try out the following code:
c#:
protected void RadGrid1_ItemCommand(object  source, Telerik.Web.UI.GridCommandEventArgs e) 
 { 
  if(e.Item.OwnerTableView.Name == "Detail"
    { 
      if (e.CommandName == RadGrid.InitInsertCommandName) 
      { 
           e.Canceled = true
           RadGrid1.EditIndexes.Clear(); 
 
           e.Item.OwnerTableView.EditFormSettings.UserControlName = "InsertForm.ascx"
           e.Item.OwnerTableView.InsertItem(); 
      }     
      else if (e.CommandName == RadGrid.EditCommandName) 
      { 
           e.Item.OwnerTableView.IsItemInserted = false
           e.Item.OwnerTableView.EditFormSettings.UserControlName = "EditForm.ascx"
      } 
    } 
 }  

Thanks
Princy.
Tags
Grid
Asked by
Charles Hayes
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or