unable to get new values from rad grid on update

4 posts, 0 answers
  1. Mubasshar
    Mubasshar avatar
    7 posts
    Member since:
    Jul 2011

    Posted 04 Jul 2011 Link to this post

    Dear Team

    i tried almost all the ways which i could find on internet but still unable to get the updated values from bound grid column.

    plz check out my code lines.

    aspx coding

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="frmViewUnitMaster.aspx.vb" Inherits="iTourism.WebForm1" %>
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <form id="form1" runat="server" >
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <table style="width:100%;">
                        <asp:Button ID="btnAdd" runat="server" Text="Add" Width="69px" />
                        <asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
                        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                                <telerik:AjaxSetting AjaxControlID="UMGrid">
                                        <telerik:AjaxUpdatedControl ControlID="UMGrid" />
        <telerik:RadGrid ID="UMGrid" runat="server" AutoGenerateColumns="False" GridLines="None"
                            AllowFilteringByColumn="True" AllowSorting="True" AutoGenerateEditColumn="True"
                            AllowPaging="True" Width="60%" ViewStateMode="Enabled" CellPadding="10"
                            CellSpacing="10" onupdatecommand="UMGrid_UpdateCommand" >
                <Selecting AllowRowSelect="True" />
                <Scrolling AllowScroll="True"  />
                <Selecting AllowRowSelect="True"></Selecting>
    <MasterTableView EditMode="EditForms" DataKeyNames="UnitCode">
            <telerik:GridBoundColumn DefaultInsertValue="" UniqueName="UnitCode"
                HeaderText="UnitCode" DataField="UnitCode" ReadOnly="True">
            <telerik:GridBoundColumn DefaultInsertValue="" UniqueName="UnitDesc"
                HeaderText ="Unit Description" DataField="Description" >
        <EditFormSettings  EditFormType="AutoGenerated"  >

    Vb Code

    Imports System
    Imports System.Data
    Imports Telerik.Web.UI
    Imports System.Data.SqlClient
    Public Class WebForm1
        Inherits System.Web.UI.Page
        Dim objclsUnitMaster As New clsUnitMaster
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            UMGrid.AutoGenerateDeleteColumn = True
            UMGrid.AutoGenerateEditColumn = True
            UMGrid.DataSource = (objclsUnitMaster.GetUnitCodeList).Tables("UnitMaster")
        End Sub
        Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
        End Sub
        Private Sub UMGrid_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles UMGrid.ItemCommand
            If (e.CommandName = RadGrid.UpdateCommandName) Then
                Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
                Dim newValues As New Hashtable
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)
       'not getting the updated value        
                lblMessage.Text = newValues("Description").ToString
            End If
        End Sub
        Private Sub UMGrid_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles UMGrid.NeedDataSource
            UMGrid.DataSource = (objclsUnitMaster.GetUnitCodeList).Tables("UnitMaster")
        End Sub
        Public Sub UMGrid_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles UMGrid.UpdateCommand
            ' Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            'Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)
            Dim _UnitCode As Integer = 0
            Dim _Description As String = ""
            Dim _Result As Long = 0
            Dim _item As GridEditableItem
            _item = e.Item
                 _UnitCode = Convert.ToInt32(DirectCast(_item("UnitCode").Controls(0), TextBox).Text)
     'Unable to Get Updated Value using this also
                _Description = DirectCast(_item("Description").Controls(0), TextBox).Text
                _Result = objclsUnitMaster.UpdateUnitByCode(_UnitCode, _Description)
                If _Result = 0 Then
                    lblMessage.Text = "Record Saved Successfully"
                    lblMessage.Text = "Error While Saving Record" & " - " & _Result
                End If
            Catch ex As Exception
                lblMessage.Text = ex.Message
            End Try
        End Sub
    End Class

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jul 2011 Link to this post

    Hello Mubasshar,

    The issue is cause you are binding the RadGrid in the pageLoad with out checking for the !Page.IsPostBack. So the it always returns the old values. The correct approach when using simple data-binding is to call the DataBind() method on the first page load when !Page.IsPostBack and after handling some event (sort event for exampleSimple data-binding through the DataBind() method can be used in simple scenarios which does not require complex operations like insert/delete/update, grouping, hierarchy relations, etc.

    And also no need to use simple dataBinding and NeedData source together. You can find more on this from the following documentation.
    Grid / Simple Data Binding.
    Grid / Advanced Data Binding.

  3. Mubasshar
    Mubasshar avatar
    7 posts
    Member since:
    Jul 2011

    Posted 05 Jul 2011 Link to this post

    thanks dear its working now.
    the other issue is that i am using the form template for updating the record. i am using asp buttons. update button is working in fire fox but not working in Internet Explorer. is something i have to change for Internet Explorer.

                        <td><asp:TextBox ID="txtDescription" MaxLength="50"  runat="server" text='<%# Bind ("Description") %>' ToolTip="Enter Description" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidatorDesc" runat="server" ControlToValidate="txtDescription" ErrorMessage="Description Is Required" ForeColor="Red" ></asp:RequiredFieldValidator></td>
    'These buttons are not working for Internet Explorer
                       <td> <asp:Button ID="btnUpdate" CommandName="Update" Text="Update" runat="server"   /> </td>
                       <td> <asp:Button ID="btnCancel" CommandName="Cancel" Text="Cancel" runat="server" /> </td>
  4. Mubasshar
    Mubasshar avatar
    7 posts
    Member since:
    Jul 2011

    Posted 05 Jul 2011 Link to this post

    any how its working if i use image button. thanks
Back to Top