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

Updating multiple items in listview updates only first item

8 Answers 318 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jeroen
Top achievements
Rank 1
Jeroen asked on 25 May 2011, 08:21 PM
I'm trying to update all items in a listview from a single place outside the listview. I've put my simplified code underneath, notice that clicking the button will update only the first item, even though the FireCommandEvent is called for both items in the list.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListViewIssue.aspx.cs"
    Inherits="RadGridSave.ListViewIssue" %>
 
<%@ Register Assembly="Telerik.Web.UI, Version=2011.1.413.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
    Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <telerik:RadListView ID="RadListView1" runat="server" AllowMultiItemEdit="true"
            onprerender="RadListView1_PreRender">
            <ItemTemplate>
                Readonly</ItemTemplate>
            <EditItemTemplate>
                Edit</EditItemTemplate>
        </telerik:RadListView>
    </div>
    <telerik:RadButton ID="RadButton1" runat="server" onclick="RadButton1_Click"
        Text="RadButton">
    </telerik:RadButton>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using Telerik.Web.UI;
 
namespace RadGridSave
{
    public partial class ListViewIssue : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadListView1.DataSource = new List<int>() { 1, 2 };
        }
 
        protected void RadListView1_PreRender(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                foreach (RadListViewDataItem item in RadListView1.Items)
                {
                    item.Edit = true;
                }
                RadListView1.Rebind();
            }
        }
 
        protected void RadButton1_Click(object sender, EventArgs e)
        {
            foreach (var item in RadListView1.EditItems)
            {          
                item.FireCommandEvent(RadListView.UpdateCommandName, string.Empty);
            }
        }
    }
}

8 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 28 May 2011, 02:10 PM
Hi Jeroen,

Please find the attached sample illustrating how you can implement batch updates with the RadListView control. Give it a try and let me know how it goes.

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 09 Dec 2020, 09:33 PM

Sorrry for the late request but I am struggling with the following situation that seems similar.

I have a RadListView, and NeedsDataSource that provides the data. It is used to populate a complex (?) user control  that presents the data in a formatted way for review and edit.  The items are assigned through properties on the UserControl, like this:

...

..

<asp:Panel ID="DocumentDetailsArea" runat="server" CssClass="dv-document-detail-area RadAjaxPanel RadAjaxPanel-full flex-col justify-start order-2 ">
                       <telerik:RadListView ID="DocumentList1" runat="server"
                           CssClass="dv-radlistview-area flex flex-row w-full order-1"
                           OnNeedDataSource="DocumentList1_NeedDataSource"
                           AllowPaging="True"
                           ItemPlaceholderID="DocumentList1PlaceHolder1"
                           DataKeyNames="Doc_Key" RenderMode="Lightweight">
                           <LayoutTemplate>
                               <%--<div id="dv-layout-template-area" class="flex flex-col justify-start border-gray-100 border-solid p-2">--%>
                               <fieldset class="w-full" id="DocumentList1">
                                   <legend></legend>
                                   <asp:PlaceHolder runat="server" ID="DocumentList1PlaceHolder1"></asp:PlaceHolder>
                               </fieldset>
                               <%--</div>--%>
                           </LayoutTemplate>
                           <%-- <ItemStyle CssClass="block px-1"></ItemStyle>--%>
                           <ItemTemplate>
                               <div class="flex flex-col w-full order-1">
                                   <uc1:SingleDocView ID="SingleDocView1" runat="server"
                                       DocKey='<%#Eval("doc_key") %>'
                                       KdotblpDocumentsGd='<%#Eval("kdotblpdocumentsgd") %>'
                                       DocType='<%#Eval("doc_type_key") %>'
                                       DocSubType='<%#Eval("doc_subtype_key") %>'
                                       DocSubTypeLabel='<%#Eval("sub_type") %>'
                                       DocLevel='<%#Eval("doc_level") %>'
                                       DocUrl='<%#Eval("target_file_name") %>'
                                       ThumbnailUrl='<%#Eval("thumb_file_name") %>'
                                       UploadedDtTmStamp='<%#Eval("uploaded_at") %>'
                                       ModifiedDtTmStamp='<%#Eval("updated_at") %>'
                                       UploadedBy='<%#Eval("uploaded_by") %>'
                                       UpdatedBy='<%#Eval("updated_by") %>'
                                       Title='<%#Eval("doc_title") %>'
                                       Editable='<%#Eval("editable") %>'
                                       Selectable='<%#Eval("selectable") %>'
                                       LRDate='<%#Eval("doc_effective_date") %>'
                                       LRProject='<%#Eval("doc_project_number") %>'
                                       LRSource='<%#Eval("doc_source") %>'
                                       DocSourceEventGd='<%#Eval("docsourceeventgd") %>'
                                       NotesLabel="Document Notes"
                                       Notes='<%#Eval("notes") %>'
                                       ShowNotes="1" />
                                   <%--DocumentNotesEditingPanel.TbxNotes.Text='<%#Eval("notes") %>'--%>
                                   <hr class="form-divider-line flex flex-row visible w-full py-1 order-2"></hr>
                               </div>
                           </ItemTemplate>
                           <ItemSeparatorTemplate>
                           </ItemSeparatorTemplate>
                           <EmptyDataTemplate>
                               <%-- <hr class="form-divider-line" />--%>
                               <div class="flex flex-col justify-center h-12 my-2 ml-4">
                                   <div class="flex flex-row  text-left  space-x-1">
                                       <i class="fas fa-hand-point-up fa-2x button-icon button-icon-blue"></i><span class="text-sm">Click on a link to view documents for each type.</span>
                                   </div>
                               </div>
                           </EmptyDataTemplate>
                       </telerik:RadListView>
                   </asp:Panel>

 

So the data gets to the properties of the usercontrol fine, but I cannot figure out how to extract the values from the user control and use them to update the columns of the  original row(s).  Any sort of hint would be welcome.  

0
Doncho
Telerik team
answered on 14 Dec 2020, 04:43 PM

Hi Allen,

The RadListView exposes EditItemTemplate which is the recommended one to use when editing entities, see Edit and Insert.

As for manual handling the Edit operations you may find it useful to review our Manual data editing demo.

In general, the bulk editing goes beyond the built-in functionalities of the RadListView. However, the sampling approach suggested by Iana in this forum thread demonstrates one way to achieve such behavior by enabling multi-item edit (AllowMultiItemEdit="true") and turning all loaded items into edit mode before rendering. The same approach can be applied to editing using WebUserControl.

I have attached a sample project for you to test. It is based on the same approach as the sample shared by Iana. Feel free to modify the sample so that it fits the current scenario.

Please let me know if any further questions come up!

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 14 Dec 2020, 09:51 PM
OK, I see what I suspected/feared.  I need to have the mildly - complicated object I am using to present data duplicated with BIND instead of EVAL in the property setting for the Edit Item template, if I am understanding this correctly.
0
Doncho
Telerik team
answered on 17 Dec 2020, 03:42 PM

That's right Allen!

In general, Bind is suitable for use in EditItemTemplate as it will pass the value to the Update method of the data source. 

You can research the difference between using Eval and Bind in multiple public resources.

Here is a StackOverflow thread about this topic - Understanding ASP.NET Eval() and Bind().

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 18 Dec 2020, 11:41 AM
So has anybody solved the problem of having the same presentation object referenced 2x in the control html once with bind and once with eval, for the editable fields?  Seems really awkward to duplicate the object. Thx.
0
Doncho
Telerik team
answered on 22 Dec 2020, 02:28 PM

Hi Allen,

The sample project I have provided earlier demonstrates a custom approach and, in its essence, it forces the RadListView control to always display all its items into edit mode. The ItemTemplate in this approach is not used at all and it can be blank. Please note that the WebUserControl is only used in the EditItemTemplate:

<ItemTemplate></ItemTemplate>
<EditItemTemplate>
    <div class="listview-item editform">
        <uc1:WebUserControl runat="server" ID="WebUserControl"
            ShipName='<%# Bind("ShipName") %>'
            ShipCountry='<%# Bind("ShipCountry") %>' />
    </div>
</EditItemTemplate>
Generally, using the same WebUserControl both for visualizing and editing data is not a common practice and it can rarely be needed.
A UserControl may contain input controls that would be needed for editings like TextBox, DropDownList, DatePicker, etc... On the other hand, such controls are usually avoided for displaying data as they provide editing functionalities. As for the ItemTemplate, it is designed for displaying data in read-only mode. If a WebUserControl is used inside the ItemTemplate it normally would contain Labels, Literals, and other read-only controls. That comes to say that in standard use cases the ItemTemplate and the EditItemTemplate would contain different controls hence the same WebUserControl can hardly be applicable for both of the control containers.

I hope this will help you get a better overview.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 22 Dec 2020, 05:53 PM
Thank you.  I will generate the separate items as you suggest, retaining the basic appearance as desired.  Happy holiday season and stay safe!
Tags
ListView
Asked by
Jeroen
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Allen
Top achievements
Rank 2
Iron
Veteran
Doncho
Telerik team
Share this question
or