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

[Solved] Retrieve DataItem on UpdateCommand

1 Answer 303 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jorge
Top achievements
Rank 1
jorge asked on 01 Oct 2009, 12:16 PM

Hi, im using the ObjectDataSource to bind Class Objects to the RadGrid.

Class

Public Function ObtenerCliente(ByVal CLI_ID As IntegerAs Cliente  
        Dim Cli As New Cliente  
        Dim Dt As DataTable = ListarClientes(CLI_ID)  
        If Not Dt.Rows.Count = 0 Then 
            Mappear(Dt.Rows(0), Cli)  
        End If 
        Cli.telefono = ObtenerTelefonos(CLI_ID)  
        Cli.domicilio = ObtenerDomicilios(CLI_ID)  
        Return Cli  
    End Function 
    Public Function ObtenerClientes() As List(Of Cliente)  
        Dim lst_Cliente As New List(Of Cliente)  
        Dim Cli As New Cliente  
        Dim Dt As DataTable = ListarClientes(0)  
        For Each Row As DataRow In Dt.Rows  
            lst_Cliente.Add(ObtenerCliente(CInt(Row("CLI_ID"))))  
        Next 
        Return lst_Cliente  
    End Function 

Page

    <telerik:radgrid runat="server" id="ClienteListado" AllowPaging="True"   
        AllowSorting="True" DataSourceID="ods_Cliente" GridLines="None" Skin="WebBlue"   
        AutoGenerateColumns="False"  >  
    <MasterTableView CellSpacing="-1" DataSourceID="ods_Cliente">  
        <Columns>  
            <telerik:GridBoundColumn DataField="CLI_ID" HeaderText="Cod" ReadOnly="true"></telerik:GridBoundColumn>  
            <telerik:GridBoundColumn DataField="CLI_RAZONSOCIAL" HeaderText="Razonsocial"></telerik:GridBoundColumn>  
            <telerik:GridBoundColumn DataField="CLI_CUIT" HeaderText="Cuit"></telerik:GridBoundColumn>  
            <telerik:GridBoundColumn DataField="CLI_EMAIL" HeaderText="Email"></telerik:GridBoundColumn>  
            <telerik:GridDropDownColumn DataField="CLI_CIVA_ID" HeaderText="IVA" DataSourceID="ods_Civa" ListTextField="CIVA_NOMBRE" ListValueField="CIVA_ID"></telerik:GridDropDownColumn>  
            <telerik:GridEditCommandColumn HeaderText="Editar" EditText="Editar" CancelText="Cancelar" ></telerik:GridEditCommandColumn>  
        </Columns>  
    </MasterTableView>  
    </telerik:radgrid>      
<asp:ObjectDataSource ID="ods_Cliente" runat="server"   
    SelectMethod="ListarClientes" TypeName="ClienteManager">  
    <SelectParameters>  
        <asp:Parameter DefaultValue="0" Name="ID" Type="Int32" />  
    </SelectParameters>  
</asp:ObjectDataSource> 

What I want is to retrieve the Class Object Binded to the current GridViewRow when the 

ClienteListado.UpdateCommand is fired.

Any idea?

 

i ve tried this but didnt work

 

 

 

Protected Sub ClienteListado_UpdateCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles ClienteListado.UpdateCommand  
 
   MsgBox(TryCast(e.Item.DataItem, Cliente).nombre)  
End Sub 
 

 

 

Regards.

Geoorge

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Oct 2009, 01:09 PM
Hello George,

e.Item.DataItem will retrieve the corresponding values only during data-binding similar to the MS DataGrid and GridView and so the DataItem object would be null after a post-back. Instead, you can try accessing the key value for the grid item and pass it to your collection to find desired item.  
Protected Sub RadGrid1_ItemCommand(source As Object, e As GridCommandEventArgs) 
    If e.CommandName = "Update" Then 
        Dim item As GridDataItem = DirectCast((DirectCast(e.CommandSource, Button)).NamingContainer, GridDataItem) 
        Dim value As Object = item.GetDataKeyValue("DataKeyName"
    End If 
End Sub 

Hope this helps..
Princy.
Tags
Grid
Asked by
jorge
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or