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

Batch update with ObjectDataSource

3 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
long
Top achievements
Rank 1
long asked on 13 Jul 2011, 05:42 AM
I have a grid that batch update with Objectdatasource as below, I can get value and set to parameter, but nothing updated to may database, please help me

<telerik:RadGrid ID="GridDD" runat="server" Width="97%" ShowStatusBar="True" AllowSorting="True"
    PageSize="20" GridLines="None" AllowPaging="True" AutoGenerateColumns="false"
    DataSourceID="diemdanh_task" Skin="Hay" EnableAJAX="true">
    <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" PageSizeLabelText="Kích cỡ" />
    <MasterTableView TableLayout="Fixed" DataKeyNames="ID" EditMode="InPlace" ClientDataKeyNames="ID"
        CommandItemDisplay="Bottom">
        <CommandItemTemplate>
            <div style="height: 30px; text-align: right;">
                <asp:Image ID="imgCancelChanges" runat="server" ImageUrl="~/DesktopModules/YourCompany.DD/Images/cancel.gif"
                    AlternateText="Cancel changes" ToolTip="Cancel changes" Height="24px" Style="cursor: pointer;
                    margin: 2px 5px 0px 0px;" onclick="CancelChanges();" />
                <asp:Image ID="imgProcessChanges" runat="server" ImageUrl="~/DesktopModules/YourCompany.DD/Images/ok.gif"
                    AlternateText="Process changes" ToolTip="Process changes" Height="24px" Style="cursor: pointer;
                    margin: 2px 5px 0px 0px;" onclick="ProcessChanges();" />
            </div>
        </CommandItemTemplate>
        <Columns>
            <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID" ReadOnly="True"
                HeaderStyle-Width="5%" Visible="false" />
            <telerik:GridBoundColumn UniqueName="ngaythang" DataField="ngaythang" HeaderText="Ngày tháng"
                ReadOnly="True" HeaderStyle-Width="5%" />
            <telerik:GridBoundColumn UniqueName="mahv" DataField="mahv" HeaderText="Mã HV" ReadOnly="True"
                HeaderStyle-Width="5%" />
            <telerik:GridBoundColumn UniqueName="hoten" DataField="hoten" HeaderText="Họ Tên"
                ReadOnly="True" HeaderStyle-Width="5%" />
            <telerik:GridBoundColumn UniqueName="ngaysinh" DataField="ngaysinh" HeaderText="Ngày Sinh"
                ReadOnly="True" HeaderStyle-Width="5%" />
            <telerik:GridTemplateColumn UniqueName="nghiphep" HeaderText="Nghỉ phép" HeaderStyle-Width="15%">
                <ItemTemplate>
                    <asp:Label ID="lblnghiphep" runat="server" Text='<%# Eval("nghiphep") %>' />
                    <asp:TextBox ID="txtnghiphep" runat="server" Text='<%# Bind("nghiphep") %>' Width="95%"
                        MaxLength="1" Style="display: none" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn UniqueName="lydo" HeaderText="Lý do" SortExpression="lydo"
                HeaderStyle-Width="10%">
                <ItemTemplate>
                    <asp:Label ID="lbllydo" runat="server" Text='<%# Eval("lydo") %>' />
                    <asp:TextBox ID="txtlydo" runat="server" Text='<%# Bind("lydo") %>' Width="95%" Style="display: none" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowCreated="RowCreated" OnRowClick="RowClick" OnCommand="RadGrid1_Command"
            OnRowDestroying="RowDestroying" />
    </ClientSettings>
</telerik:RadGrid>

And my objectsatasource as :
<asp:ObjectDataSource ID="diemdanh_task" runat="server" DataObjectTypeName="YourCompany.Modules.DD.DDInfo"
    SelectMethod="DD_GetAll" TypeName="YourCompany.Modules.DD.DDController" UpdateMethod="DD_Update"
    OnInit="Page_Load">
    <SelectParameters>
        <asp:Parameter Name="fromdate" DefaultValue="07/11/2011" DbType="String" />
    </SelectParameters>
    <UpdateParameters>
       <asp:Parameter Name="nghiphep" DbType="String" />
      <asp:Parameter Name="lydo" DbType="String" />
       <asp:Parameter Name="ID" DbType="String" />
    </UpdateParameters>
</asp:ObjectDataSource>
Datacontroller :
Public Class DDController
      <DataObjectMethod(DataObjectMethodType.Select)> Public Shared Function DD_GetAll(ByVal fromdate As String) As List(Of DDInfo)
          Return CBO.FillCollection(Of DDInfo)(DataProvider.Instance.GetAllDD(fromdate))
      End Function
      <DataObjectMethod(DataObjectMethodType.Update)> Public Shared Sub DD_Update(ByVal objest As DDInfo)
          DataProvider.Instance.UpdateDD(objest.nghiphep, objest.Lydo, objest.ID)
      End Sub
  End Class
InfoClass :
Namespace YourCompany.Modules.DD
    Public Class DDInfo
        Private _mahv As String
        Private _ngaythang As String
        Private _nghiphep As String
        Private _lydo As String
        Private _ID As String
        Private _ngaysinh As String
        Private _hoten As String
        Public Property ID() As String
            Get
                Return _ID
            End Get
            Set(ByVal value As String)
                _ID = value
            End Set
        End Property
        Public Property ngaythang() As String
            Get
                Return _ngaythang
            End Get
            Set(ByVal value As String)
                _ngaythang = value
            End Set
        End Property
        Public Property mahv() As String
            Get
                Return _mahv
            End Get
            Set(ByVal value As String)
                _mahv = value
            End Set
        End Property
        Public Property hoten() As String
            Get
                Return _hoten
            End Get
            Set(ByVal value As String)
                _hoten = value
            End Set
        End Property
 
        Public Property ngaysinh() As String
            Get
                Return _ngaysinh
            End Get
            Set(ByVal value As String)
                _ngaysinh = value
            End Set
        End Property
     
        Public Property nghiphep() As String
            Get
                Return _nghiphep
            End Get
            Set(ByVal value As String)
                _nghiphep = value
            End Set
        End Property
        Public Property Lydo() As String
            Get
                Return _lydo
            End Get
            Set(ByVal value As String)
                _lydo = value
            End Set
        End Property
 
 
    End Class
And server-side code :
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
    If e.Argument = String.Empty Then
        GridDD.Rebind()
    End If
    Dim editedItemIds As String() = e.Argument.Split(":")
    Dim i As Integer
    For i = 0 To editedItemIds.Length - 2
        Dim ID As String = editedItemIds(i)
        Dim updatedItem As GridDataItem = CType(GridDD.MasterTableView.FindItemByKeyValue("ID", ID), GridDataItem)
        UpdateValues(updatedItem)
        GridDD.DataBind()
    Next
End Sub
Protected Sub UpdateValues(ByVal updatedItem As GridDataItem)
    Dim txtBox As TextBox = CType(updatedItem.FindControl("txtnghiphep"), TextBox)
    diemdanh_task.UpdateParameters("nghiphep").DefaultValue = txtBox.Text
    txtBox = CType(updatedItem.FindControl("txtlydo"), TextBox)
    diemdanh_task.UpdateParameters("lydo").DefaultValue = txtBox.Text
    diemdanh_task.UpdateParameters("ID").DefaultValue = updatedItem.GetDataKeyValue("ID").ToString()
 
    Try
        diemdanh_task.Update()
    Catch ex As Exception
        SetMessage(Server.HtmlEncode("Không thể cập nhật ngày phép. Lỗi: " + ex.StackTrace).Replace("'", "'").Replace(vbCrLf, "<br />"))
    End Try
    SetMessage("Đã cập nhật ngày phép học viên : " & updatedItem.Item("mahv").Text)
End Sub

3 Answers, 1 is accepted

Sort by
0
Pavel
Telerik team
answered on 18 Jul 2011, 09:33 AM
Hello Long,

I cannot see the reasons for your problem just by looking at the provided code. I can recommend you to check this example illustrating how to implement batch updates for the Grid. If that does not help, consider opening a support ticket and sending a runnable sample which illustrates the issue.

Regards,
Pavel
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
long
Top achievements
Rank 1
answered on 18 Jul 2011, 10:16 AM
Hi Admin,
A long time for your reply
I have corrected this error
please close this topic

Thanks
0
Genaro
Top achievements
Rank 1
answered on 22 Nov 2011, 04:06 PM
dear, how you soluction its?  I AM same problem
Tags
Grid
Asked by
long
Top achievements
Rank 1
Answers by
Pavel
Telerik team
long
Top achievements
Rank 1
Genaro
Top achievements
Rank 1
Share this question
or