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

unable to retrieve value from editedItem..

5 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milan Gurung
Top achievements
Rank 1
Milan Gurung asked on 01 Sep 2008, 03:06 PM
Hi,

Following one of your tutorial, I was trying to edit/update record in the grid - the problem I am having is that for every editedItem returned blank..Following is the aspx and code behind file...Any help would be greatly appreciated..

Thanks.


<%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Test.aspx.vb" Inherits="ProjectTemplar.Test"
    title="Untitled Page" EnableViewState="true"%>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <asp:Label ID="lblErrorMsg" runat="server" CssClass="errorFont"></asp:Label>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
    OnNeedDataSource="RadGrid1_NeedDataSource"
    OnUpdateCommand="RadGrid1_UpdateCommand">
        <MasterTableView EditMode="InPlace">
        <Columns>
         <telerik:GridEditCommandColumn UpdateText="Update" EditText="Edit" CancelText="Cancel"></telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn DataField="BudgetExceptionID" Visible="TRUE" HEADERTEXT = "BudgetExceptionID" UniqueName="BudgetExceptionID" readonly="true"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ExceptionNotes" HeaderText="Exp. Notes" UniqueName="ExceptionNotes" ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Budget_DATETIME" HeaderText="Date &amp; Time">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="EffectivePeriod" HeaderText="Effective Period"
                    UniqueName="EffectivePeriod">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
</asp:Content>

--Code Behind ---

Imports Telerik.Web.UI
Partial Public Class Test
    Inherits System.Web.UI.Page

    Private ReadOnly Property GridSource() As DataTable
        Get
            Dim obj As Object = Me.ViewState("_gds")
            If (Not obj Is Nothing) Then
                Return CType(obj, DataTable)
            Else
                Dim table As DataTable = Nothing
                Try
                    Dim ds As DataSet
                    Dim batchManager As New DataBatchManager()
                    ds = batchManager.GetBudgetExceptionsByBatchID(34)
                    table = ds.Tables(0)
                    Me.ViewState("_gds") = table
                    Return table
                Catch ex As Exception
                    lblErrorMsg.Text = ex.Message
                End Try
                Return table
            End If
        End Get
    End Property

    Protected Sub RadGrid1_NeedDataSource(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = Me.GridSource
    End Sub
    Protected Sub RadGrid1_UpdateCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
        Dim ordersTable As DataTable = Me.GridSource
        Dim id As String
        id = editedItem("Client").Text  '...returns blank..
        lblErrorMsg.Text = "Hello " + id.ToString()
    End Sub

5 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 01 Sep 2008, 03:12 PM
Hi Milan,

If a TableCell have controls in the Controls collection Text property will be empty. You can access the value using the Controls collection approach. Here is an example for TextBox:

CType(editedItem("Client").Controls(0), TextBox).Text 

If you want to retrieve an key name value you can use DataKeyNames/DataKeyValues:

If TypeOf e.Item Is GridDataItem Then

  Dim value As String  = CType(e.Item, GridDataItem).GetDataKeyValue("MyKeyName")

End If
...
<MasterTableView DataKeyNames="MyKeyName" ...

Kind regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Milan Gurung
Top achievements
Rank 1
answered on 01 Sep 2008, 03:37 PM
Thanks a lot Vlad.

Cheers,
Milan G
0
Princy
Top achievements
Rank 2
answered on 02 Sep 2008, 09:02 AM
Hi Milan,

You can also check out the demo sample on how to access cells and rows

http://demos.telerik.com/aspnet/Grid/Examples/Programming/AccessingCellsAndRows/DefaultCS.aspx

Hope this is useful to you.

Thanks,
Princy  
0
jlehew
Top achievements
Rank 1
answered on 15 Oct 2008, 09:32 PM
I noticed that the example above doesn't work right.  Updating values doesn't work and it clears all the checkboxes when it goes into edit mode.

Thanks,
John
0
Yavor
Telerik team
answered on 16 Oct 2008, 05:31 AM
Hi jlehew,

Indeed, the control will clear the checkboxes- this is because when it goes into edit mode, it rebinds. If you would like to persist their state, you will need to use custom code to persist the selection.
I hope this information helps.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Milan Gurung
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Milan Gurung
Top achievements
Rank 1
Princy
Top achievements
Rank 2
jlehew
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or