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

Two different Update Forms

3 Answers 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
M S
Top achievements
Rank 1
M S asked on 09 Jun 2010, 01:13 PM

Refering to the example http://www.telerik.com/community/forums/aspnet-ajax/grid/two-different-insert-forms.aspx#720782 pls let me know this : pls

 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

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jun 2010, 01:42 PM
Hello,

I guess you want to show panel2 as editform. If so modify the code in ItemDataBound as shwon below.

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


Regards,
Princy.
0
M S
Top achievements
Rank 1
answered on 09 Jun 2010, 01:57 PM
Thanks in advance for a fast reply. Here is my situation. I have an item master table with the follwowing columns :
Item Code, Desc, Price, newstock, issuestock.
In the Add new record only ItemCode, Desc and Price will be entered. Other two fields are not entered initially.
Now the grid should have three command button in every row. One for edit (for above fields inserted)
Another button for Update which will have have only one textbox and that will update newstock
A third button for Update which will have only one textbox but this time for updating the issuestock textbox only.

I use automatic operation for insert and edit. But can use manual mode for the two update button.

Pls help...
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Jun 2010, 02:50 PM
Hello,

Here is the sample code for achieving yuor requirement. I hope this would work for you.

ASPX:
 
<EditFormSettings EditFormType="Template">  
    <FormTemplate> 
        <asp:Panel ID="Panel1" runat="server">  
            <asp:TextBox ID="TextBox1" runat="server" Text="ItemCode"></asp:TextBox> 
            <asp:TextBox ID="TextBox2" runat="server" Text="Price"></asp:TextBox> 
        </asp:Panel> 
        <asp:Panel ID="Panel2" runat="server" Visible="false">  
            <asp:TextBox ID="newStock" runat="server" Text="Integer"></asp:TextBox> 
              <asp:Button ID="Button4" runat="server" Text="Button" CommandName="updateNew" /> 
        </asp:Panel> 
        <asp:Panel ID="Panel3" runat="server" Visible="false">  
            <asp:TextBox ID="issueStock" runat="server" Text="String"></asp:TextBox> 
              <asp:Button ID="Button5" runat="server" Text="Button" CommandName="updateIssued" /> 
        </asp:Panel> 
        
    </FormTemplate> 
</EditFormSettings> 

CS:
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)  
    {  
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
        {  
            GridEditFormItem editItem = (GridEditFormItem)e.Item;  
            if (updateNew == "newStock")  
            {  
                editItem.FindControl("Panel1").Visible = false;  
                editItem.FindControl("Panel2").Visible = true;  
                editItem.FindControl("Panel3").Visible = false;  
            }  
            if (updateIssued == "issueStock")  
            {  
                editItem.FindControl("Panel1").Visible = false;  
                editItem.FindControl("Panel2").Visible = false;  
                editItem.FindControl("Panel3").Visible = true;  
            }  
        }  
    }  
    string updateNew;  
    string updateIssued;  
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)  
    {  
        if (e.CommandName == "newStock")  
        {  
            updateNew = "newStock";  
            e.Item.Edit = true;  
            RadGrid1.Rebind();  
        }  
        else if (e.CommandName == "issueStock")  
        {  
            updateIssued = "issueStock";  
            e.Item.Edit = true;  
            RadGrid1.Rebind();  
        }  
        if (e.CommandName == "updateNew")  
        {  
            TextBox txtBox = (TextBox)(e.Item as GridDataItem).EditFormItem.FindControl("newStock");  
            string value = txtBox.Text; // Here prepare the query to update newStock  
        }  
        else if (e.CommandName == "updateIssued")  
        {  
            TextBox txtBox = (TextBox)(e.Item as GridDataItem).EditFormItem.FindControl("issueStock");           
            string value = txtBox.Text; // Here prepare the query to update issueStock  
        }         
    } 


Regards,
Princy.
Tags
Grid
Asked by
M S
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
M S
Top achievements
Rank 1
Share this question
or