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

Update radlistview with objectdatasource

1 Answer 81 Views
This is a migrated thread and some comments may be shown as answers.
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%">
          <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%">
               <telerik:RadDataPager ID="RadDataPager1"
                                 runat="server" PagedControlID="radListView" 
                 <telerik:RadDataPagerButtonField FieldType="FirstPrev"></telerik:RadDataPagerButtonField>
                 <telerik:RadDataPagerButtonField FieldType="Numeric" ></telerik:RadDataPagerButtonField>
                 <telerik:RadDataPagerButtonField FieldType="NextLast"></telerik:RadDataPagerButtonField>
                 <telerik:RadDataPagerGoToPageField SubmitButtonText="Go" TextBoxWidth="15" />
                       <div style="float: right">
                       <asp:Label runat="server" ID="CurrentPageLabel"
                                                   Text="<%# Container.Owner.StartRowIndex+1%>" />
                       <asp:Label runat="server" ID="TotalPagesLabel"
                                                   Text="<%# Container.Owner.StartRowIndex+Container.Owner.PageSize %>" />
                       <asp:Label runat="server" ID="TotalItemsLabel"
                                                   Text="<%# Container.Owner.TotalRowCount%>" />
                       <br />
<asp:PlaceHolder ID="PlaceHolder" runat="server"></asp:PlaceHolder>
<br >
          <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 class="divForm" style="text-align: left">
         <label class="labelFormulario">Factory :</label>
         <asp:Label ID="Label10" runat="server" Text='<%# Eval("Factory")%>'></asp:Label>
   <div class="divForm" style="text-align: left">
         <label class="labelForm">Amount :</label>
         <asp:Label ID="Label11" runat="server" Text='<%# Eval("Amount")%>'></asp:Label>
   <div class="divForm" style="text-align: left">
         <label class="labelForm">Total Price :</label>
         <asp:Label ID="Label15" runat="server" Text='<%# Eval("TotalPrice")%>'></asp:Label>
   <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" class="edit button"></asp:Button>
 <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 class="divForm" style="text-align: left">
        <label class="labelForm">Factory:</label>
        <telerik:RadTextBox ID="txtFactory" runat="server" Text='<%# Eval("Factory")%>'></telerik:RadTextBox>
    <div class="divForm" style="text-align: left">
        <label class="labelForm">Quantidade :</label>
        <telerik:RadNumericTextBox ID="txtAmount" runat="server" Value='<%#Eval("Amount")%>' ></telerik:RadNumericTextBox>
    <div class="divForm" style="text-align: left">
        <label class="labelFormulario">Total Price :</label>
        <telerik:RadNumericTextBox ID="txtTotalPrice" runat="server" Value='<%#Eval("TotalPrice")%>'></telerik:RadNumericTextBox>
    <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>

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

1 Answer, 1 is accepted

Sort by
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: (second grid bound to ObjectDataSource)

I hope this helps.

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.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question