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

Update radlistview with objectdatasource

1 Answer 81 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Rafael
Top achievements
Rank 1
Rafael asked on 02 Jan 2014, 12:38 PM
Hi, Telerik's team

I am with a problem on try perform updates in my radlistview filled by an objectdatasource.

I can put my radlistview in edit mode using "commands", but I cant update the data.

I used the template displayed in the radlistview page to create my page, but there are not example about how to make updates in radlistview using objectdatasource.

Please, give me a way to update data in control and after edition end, I wanna get the edited data and save in my database.



<telerik:RadListView ID="radListView" ItemPlaceholderID="CustomersContainer"
runat="server" OnItemCommand="radListView_ItemCommand"
DataKeyNames="ID" AllowPaging="True"  PageSize="1" Width="90%">
     <LayoutTemplate>
          <fieldset id="fsRadListView" style="width: 1000px !important;">
   <legend style="margin:0px 0px 0px 15px !important">Empr├ęstimos</legend>
        <table cellpadding="0" cellspacing="0" width="100%">
           <tr>
             <td>
               <telerik:RadDataPager ID="RadDataPager1"
                                 runat="server" PagedControlID="radListView" 
PageSize="1">
                 <Fields>
                 <telerik:RadDataPagerButtonField FieldType="FirstPrev"></telerik:RadDataPagerButtonField>
                 <telerik:RadDataPagerButtonField FieldType="Numeric" ></telerik:RadDataPagerButtonField>
                 <telerik:RadDataPagerButtonField FieldType="NextLast"></telerik:RadDataPagerButtonField>
                 <telerik:RadDataPagerGoToPageField SubmitButtonText="Go" TextBoxWidth="15" />
                 <telerik:RadDataPagerTemplatePageField>
                    <PagerTemplate>
                       <div style="float: right">
                         <b>Items
                       <asp:Label runat="server" ID="CurrentPageLabel"
                                                   Text="<%# Container.Owner.StartRowIndex+1%>" />
                       to
                       <asp:Label runat="server" ID="TotalPagesLabel"
                                                   Text="<%# Container.Owner.StartRowIndex+Container.Owner.PageSize %>" />
                       of
                       <asp:Label runat="server" ID="TotalItemsLabel"
                                                   Text="<%# Container.Owner.TotalRowCount%>" />
                       <br />
                        </b>
                      </div>
                  </PagerTemplate>
                </telerik:RadDataPagerTemplatePageField>
               </Fields>
              </telerik:RadDataPager>
             </td>
            </tr>
         </table>
      </fieldset>
<asp:PlaceHolder ID="PlaceHolder" runat="server"></asp:PlaceHolder>
<br >
      </LayoutTemplate>
      <ItemTemplate>
          <fieldset class="fieldSetBackgroud">
    <div class="divForm" style="text-align: left">
         <label class="labelForm">Product :</label>
         <asp:Label ID="lblProduto" runat="server" Text='<%# Eval("ProductName")%>'></asp:Label>
   </div>
   <div class="divForm" style="text-align: left">
         <label class="labelFormulario">Factory :</label>
         <asp:Label ID="Label10" runat="server" Text='<%# Eval("Factory")%>'></asp:Label>
   </div>
   <div class="divForm" style="text-align: left">
         <label class="labelForm">Amount :</label>
         <asp:Label ID="Label11" runat="server" Text='<%# Eval("Amount")%>'></asp:Label>
   </div>
   <div class="divForm" style="text-align: left">
         <label class="labelForm">Total Price :</label>
         <asp:Label ID="Label15" runat="server" Text='<%# Eval("TotalPrice")%>'></asp:Label>
   </div>
   <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" class="edit button"></asp:Button>
 </fieldset>
       </ItemTemplate>
       <EditItemTemplate>
 <fieldset class="fieldSetBackgroud">
    <div class="divForm" style="text-align: left">
        <label class="labelForm">Product:</label>
        <asp:Label  runat="server" Text='<%# Eval("ProductName")%>'></asp:Label>
    </div>
    <div class="divForm" style="text-align: left">
        <label class="labelForm">Factory:</label>
        <telerik:RadTextBox ID="txtFactory" runat="server" Text='<%# Eval("Factory")%>'></telerik:RadTextBox>
    </div>
    <div class="divForm" style="text-align: left">
        <label class="labelForm">Quantidade :</label>
        <telerik:RadNumericTextBox ID="txtAmount" runat="server" Value='<%#Eval("Amount")%>' ></telerik:RadNumericTextBox>
    </div>
    <div class="divForm" style="text-align: left">
        <label class="labelFormulario">Total Price :</label>
        <telerik:RadNumericTextBox ID="txtTotalPrice" runat="server" Value='<%#Eval("TotalPrice")%>'></telerik:RadNumericTextBox>
    </div>
    <asp:Button ID="btnUpdate" runat="server" Text="Update Item" CommandName="Update" ToolTip="Apply changes."></asp:Button>
    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" ></asp:Button>
 </fieldset>
        </EditItemTemplate>
</telerik:RadListView>

<asp:ObjectDataSource ID="objectdatasource" runat="server" SelectMethod="ListItems"
                    TypeName="...my namespace..."></asp:ObjectDataSource>

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 07 Jan 2014, 09:51 AM
Hi Rafael,

In order the RadListView to pass appropriate parameters to the update method of the ObjectDataSource control you need to change all Evals with Bind function into to the EditItemTemplate like is shown into the following online example:
http://demos.telerik.com/aspnet-ajax/listview/examples/dataediting/net2automaticdataediting/defaultcs.aspx (second grid bound to ObjectDataSource)

I hope this helps.

Regards,
Radoslav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
ListView
Asked by
Rafael
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or