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

Two different Insert Forms

5 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 16 Jan 2009, 02:20 AM
New RadControls user here still learning the controls ins and outs.

I'd like to know if there is a way to have two different insert forms.  I have a requirement that would allow the user to be able to insert a single record or enter records in a batch type mode. 
For example: In single the user may input:  Title, Volume Number, Issue Number

In a batch mode the user would input:  Title, Volume Number Start, Volume Number End, Issue Number Start, Issue Number End

I'm assuming to do this I'd have to somehow assign a secondary link command to "Batch Insert" and somehow hook this up to the Grid to allow for a secondary insert popup to appear.

Is this possible?  Are there any examples that would help me solve this requirement or point me in the right direction.

thanks

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Jan 2009, 11:19 AM
Hello Michael,

You can place the buttons in the CommandItemTemplate and set its CommandNames accordingly. Use a Custom EditFormTemplate and place two panels in it. In one panel you can place the controls required for single record mode and in the other panel place the required controls for batch type mode respectively. Then in the ItemCommand event of the grid check for the CommandNames of the buttons and hide the panels accordingly in the ItemDataBound event of the grid as shown below:
aspx:
  <EditFormSettings EditFormType="Template"
        <FormTemplate> 
            <asp:Panel ID="Panel1" runat="server"
                <asp:TextBox ID="TextBox1" runat="server" Text="Title"></asp:TextBox> 
                <asp:TextBox ID="TextBox2" runat="server" Text="Volume Number"></asp:TextBox> 
            </asp:Panel> 
             
            <asp:Panel ID="Panel2" runat="server"
                <asp:TextBox ID="TextBox3" runat="server" Text="Title"></asp:TextBox> 
                <asp:TextBox ID="TextBox4" runat="server" Text="Volume Number Start"></asp:TextBox> 
                <asp:TextBox ID="TextBox5" runat="server" Text="Volume Number End"></asp:TextBox>                 
            </asp:Panel>            
        </FormTemplate> 
  </EditFormSettings> 

cs:
    string insert1; 
    string insert2; 
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        if (e.CommandName == "BatchModeInsert") 
        {             
            e.Item.OwnerTableView.IsItemInserted = true
            insert1 = "BatchModeInsert"
            RadGrid1.Rebind();             
        } 
 
        if (e.CommandName == "SingleModeInsert") 
        { 
            e.Item.OwnerTableView.IsItemInserted = true
            insert2 = "SingleModeInsert"
            RadGrid1.Rebind();             
        }         
    } 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item.OwnerTableView.IsItemInserted && e.Item is GridEditFormInsertItem) 
        { 
            GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item; 
            if (insert1 == "BatchModeInsert") 
            { 
                item.FindControl("Panel1").Visible = false
            } 
            if (insert2 == "SingleModeInsert") 
            { 
                item.FindControl("Panel2").Visible = false
            } 
        } 
    } 

Thanks
Princy.
0
Michael
Top achievements
Rank 1
answered on 19 Jan 2009, 08:37 PM
That did the trick!!! Thanks!!
0
M S
Top achievements
Rank 1
answered on 08 Jun 2010, 09:12 PM
Hi Princy,
   For the same solution, how do I attach Panel2, such that it acts as an update record form something like this :

 Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If e.CommandName = "BatchModeInsert" Then
            e.Item.OwnerTableView.IsItemInserted = True
            insert1 = "BatchModeInsert"
            Me.RadGrid1.Rebind()
        End If

        If e.CommandName = "SingleModeInsert" Then
            e.Item.OwnerTableView.IsItemInserted = True
            insert2 = "SingleModeInsert"
            Me.RadGrid1.Rebind()
        End If

        If e.CommandName = "Update" Then
            e.Item.OwnerTableView.IsItemInserted = True
            insert3 = "Update"
            Me.RadGrid1.Rebind()
        End If

    End Sub

 

And then in the ItemDatabound : 

 

    Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If e.Item.OwnerTableView.IsItemInserted And TypeOf (e.Item) Is GridEditFormInsertItem Then
            Dim item As GridEditFormInsertItem = TryCast(e.Item, GridEditFormInsertItem)

            If insert1 = "BatchModeInsert" Then
                item.FindControl("Panel1").Visible = False
            End If

            If insert2 = "SingleModeInsert" Then
                item.FindControl("Panel2").Visible = False
            End If

            If insert3 = "Update" Then
                item.FindControl("Panel2").Visible = False
            End If

        End If

    End Sub

 

 

I'm sure I need to add some flag that will bring up the update form for the row.

Note: I will have three buttons in the edit item template column with commandName 
BatchModeInsert, SingleModeInsert and third one with commandname set to "Update" and will use the same panel "Panel2" for update. pls know that I am using automatic operations for update and manual for insert

0
Princy
Top achievements
Rank 2
answered on 09 Jun 2010, 02:00 PM
Hello,

You can set the Visible property of panel1 to "false" when grid in edit mode, if you want to show only panel2 for updating.

C#:
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)    
    {    
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)    
        {    
            GridEditFormItem editItem = (GridEditFormItem)e.Item;    
            editItem.FindControl("Panel1").Visible = false;    
        }    
    }  

Also you can try different usercontriols for achieving similar functionality as described in the following documentation.
Different edit forms on edit and insert

Please modify the logic according to your need.


Regards,
Princy.
0
M S
Top achievements
Rank 1
answered on 18 Jun 2010, 07:15 PM
Ok now.. it all worked well..
Now I wanted the same on custom command item template.. everything works as in example

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand  
 
        If e.CommandName = "EditSelected" Then  
            curCommand = "EditSelected" 
        End If  
           
 
         
        If e.CommandName = "Edit" Then  
            e.Item.OwnerTableView.IsItemInserted = False 
            curCommand = "Edit" 
            Me.RadGrid1.Rebind()  
        End If  
 
        If e.CommandName = "Order" Then  
            e.Item.OwnerTableView.IsItemInserted = False 
            curCommand = "Order" 
            e.Item.Edit = True 
            Me.RadGrid1.Rebind()  
        End If  
............... 
Pls notice the e.item.edit = True in "order", its not setting here to True, I tried debugging, but the e.Item.Edit valu is false always..

 <CommandItemTemplate> 
<div style="padding: 5px 5px;">  
    Custom command item template&nbsp;&nbsp;&nbsp;&nbsp;  
    <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count = 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" />Edit selected</asp:LinkButton>&nbsp;&nbsp;  
      
     <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Order" Visible='<%# RadGrid1.EditIndexes.Count = 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/order.png" />Order selected</asp:LinkButton>&nbsp;&nbsp;  
    <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Issue" Visible='<%# RadGrid1.EditIndexes.Count = 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/issue.png" />Issue selected</asp:LinkButton>&nbsp;&nbsp;..........  
     
like this in aspx page
pls help.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Michael
Top achievements
Rank 1
M S
Top achievements
Rank 1
Share this question
or