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

how toupdate multiple rows at once using commanditemtemplate

5 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Babu Puchakayala
Top achievements
Rank 1
Babu Puchakayala asked on 14 Jul 2010, 09:43 PM
Hi,

I am using CommandItemtemplate in radgrid. I want to update multiple rows as shown in this demo.

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx

When I am trying to update multiple rows I am unable to update it. How to update mulltiple rows in editformtemplate.

Here is my code for single row update

<CommandItemTemplate>
                                <table>
                                    <tr>
                                        <td align="left">
                                            <b>Bulk Actions</b>    
                                        </td>
                                        <td align="left">
                                            <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# rg200.EditIndexes.Count == 0 %>'><img  style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" />Edit selected</asp:LinkButton>
                                                
                                        </td>
                                        <td align="left">
                                            <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# rg200.EditIndexes.Count >  0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Update.gif" />Update</asp:LinkButton>
                                                
                                        </td>
                                        <td align="left">
                                            <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# rg200.EditIndexes.Count > 0 || rg200.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Cancel.gif" />Cancel editing</asp:LinkButton>
                                                
                                        </td>
                                        <td align="right">
                                            <img style="border: 0px; vertical-align: middle;" alt="" src="Images/AddRecord.gif" />
                                        </td>
                                        <td align="left">
                                            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !rg200.MasterTableView.IsItemInserted %>'>Add New Record</asp:LinkButton>
                                                
                                        </td>
                                        <td align="right">
                                            <img style="border: 0px; vertical-align: middle;" alt="" src="Images/Delete.gif" />
                                        </td>
                                        <td align="left">
                                            <asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected Records?')"
                                                runat="server" CommandName="DeleteSelected">Delete Selected</asp:LinkButton>
                                                
                                        </td>
                                        <td align="right">
                                            <img style="border: 0px; vertical-align: middle;" alt="" src="Images/Refresh.gif" />
                                        </td>
                                        <td align="left">
                                            <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Rebind">Refresh</asp:LinkButton>
                                             
                                        </td>
</tr>
                                </table>
                            </CommandItemTemplate>


clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();
GridEditableItem editedItem = e.Item as GridEditableItem;
 
string OrdID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["orderId"].ToString();
string ClarifyAccountNbr = (editedItem.FindControl("TextBox1") as TextBox).Text;
string SiteID = (editedItem.FindControl("TextBox2") as TextBox).Text;
string QuoteID = (editedItem.FindControl("TextBox3") as TextBox).Text;
CheckBox chkEDP = (editedItem.FindControl("CheckBox1") as CheckBox);
try
{
    objBL.setTask200_Bl(OrdID, ClarifyAccountNbr, SiteID, QuoteID, chkEDP.Checked);
    Session["SearchRes"] = null;
    rg200.Rebind();
}
catch (Exception ex)
{
    rg200.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));
    e.Canceled = true;
}


when i am trying to update multiple rows with foreach  I am unable to update it.
if (e.CommandName == "UpdateEdited")
        {
            foreach (GridEditableItem editedItem in rg200.EditItems)
            {
                GridDataItem dataitem = editedItem as GridDataItem;
                clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();
 
                string OrdID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["orderId"].ToString();
 
                string ClarifyAccountNbr = (editedItem.FindControl("TextBox1") as TextBox).Text;
                string SiteID = (editedItem.FindControl("TextBox2") as TextBox).Text;
                string QuoteID = (editedItem.FindControl("TextBox3") as TextBox).Text;
                CheckBox chkEDP = (editedItem.FindControl("CheckBox1") as CheckBox);
                try
                {
                    objBL.setTask200_Bl(OrdID, ClarifyAccountNbr, SiteID, QuoteID, chkEDP.Checked);
                    Session["SearchRes"] = null;
                    rg200.Rebind();
                }
                catch (Exception ex)
                {
                    rg200.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));
                    e.Canceled = true;
                }
                 
            }
        }


 I tried to use hashtable, but still i am getting older values. Please help me how to update multiple rows at a time.

This is my editformsettings code

<EditFormSettings EditFormType="Template">
                                <FormTemplate>
                                    <table id="Table1" cellspacing="1" cellpadding="1">
                                        <tr>
                                            <td>
                                                <telerik:RadTabStrip runat="server" ID="RadTabStrip1" Orientation="HorizontalTop"
                                                    SelectedIndex="0" MultiPageID="RadMultiPage1">
                                                    <Tabs>
                                                        <telerik:RadTab Text="Task Data" PageViewID="RadPageView1">
                                                        </telerik:RadTab>
                                                        <telerik:RadTab Text="Notes" PageViewID="RadPageView2">
                                                        </telerik:RadTab>
                                                    </Tabs>
                                                </telerik:RadTabStrip>
                                                <telerik:RadMultiPage runat="server" ID="RadMultiPage1" SelectedIndex="0">
                                                    <telerik:RadPageView runat="server" ID="RadPageView1">
                                                        <table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
                                                            <tr>
                                                                <td>
                                                                </td>
                                                                <td>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Clarify Account Nbr:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval( "Clarify Account Nbr" ) %>'>
                                                                    </asp:TextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Site ID:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval( "Site ID") %>' TabIndex="1">
                                                                    </asp:TextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Quote ID:
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval( "Quote ID") %>' TabIndex="2">
                                                                    </asp:TextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    EDP Created?:
                                                                </td>
                                                                <td>
                                                                    <asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval( "EDP Created?") %>' TabIndex="3">
                                                                    </asp:CheckBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right" colspan="2">
                                                                    <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                                        runat="server" CommandName='Update'></asp:Button
                                                                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                                        CommandName="Cancel"></asp:Button>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </telerik:RadPageView>
                                                    <telerik:RadPageView runat="server" ID="RadPageView2">
                                                    </telerik:RadPageView>
                                                </telerik:RadMultiPage>
                                            </td>
                                        </tr>
                                    </table>
                                </FormTemplate>
                            </EditFormSettings>


Thanks
Babu


5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 15 Jul 2010, 03:43 PM
Hello Babu,

You need the following change to your code:

if (e.CommandName == "UpdateEdited"
        
            foreach (GridEditableItem editedItem in rg200.EditItems) 
            
                GridDataItem dataitem = editedItem as GridDataItem; 
                GridEditFormItem editForm = dataItem.EditFormItem; 
                Hashtable newValues = new Hashtable(); 
                editForm(newValues); 
                clsTaskUpdates_BL objBL = new clsTaskUpdates_BL(); 
                    
                //now you can use the newValues collection to get the updated field values. 
... 
... 
... 
...

Hope it helps.

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Babu Puchakayala
Top achievements
Rank 1
answered on 16 Jul 2010, 02:19 AM
Hi Tsvetoslav,

 am getting error like 'editForm' is a 'variable' but is used like a 'method'
0
Tsvetoslav
Telerik team
answered on 16 Jul 2010, 01:15 PM
Hi Babu,

Are you using the EditForm as a method member (dataItem.EditForm() )? If so, it is incorrect, as EditForm is a property. Do take a look at the code snippets in my previous post.

Best wishes,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Babu Puchakayala
Top achievements
Rank 1
answered on 16 Jul 2010, 02:37 PM
Hi,

This is my code. I did exactly how said in previous post...

if (e.CommandName == "UpdateEdited")
        {
            foreach (GridEditableItem editedItem in rg200.EditItems)
            {
                GridDataItem dataitem = editedItem as GridDataItem;
                GridEditFormItem editForm = dataitem.EditFormItem;
                Hashtable newValues = new Hashtable();
                editForm(newValues);
                clsTaskUpdates_BL objBL = new clsTaskUpdates_BL();
       
                ---------------------------

            }
       }
0
Tsvetoslav
Telerik team
answered on 19 Jul 2010, 03:20 PM
Hello Babu,

Sorry for the oversight on my part. Try chaning editForm(newValues) to editForm.ExtractValues(newValues).

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Babu Puchakayala
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Babu Puchakayala
Top achievements
Rank 1
Share this question
or