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

how toupdate multiple rows at once using commanditemtemplate

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raj
Top achievements
Rank 1
Raj asked on 15 Jul 2010, 02:33 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

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 20 Jul 2010, 07:40 AM
Hello Raj,

Upon updating the given row: objBL.setTask200_Bl(OrdID, ClarifyAccountNbr, SiteID, QuoteID, chkEDP.Checked);

you should not be rebinding the grid. Try removing the call to the grid's Rebind() method from the command event. More information you can find at our online example on Advanced vs. Simple databinding and the related help topics.

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
Tags
Grid
Asked by
Raj
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or