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

Grid Advanced Databinding InPlace Edit results in No Records to Display

2 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 04 Sep 2012, 08:56 PM
Good Afternoon all,

I am hoping to get some help with a simple grid setup that I am working on. I am researching how the Rad Grid control works in order to use it in our production environment. I have little knowledge of the control or its interworkings. I've read through the online documentation and have tried to recreate the example demo with focus toward how I would use it in production. I have a basic Dataset whichi I populate manually for my example. On the aspx page i'm using a basic RadGrid and set the OnNeedDatatSource, I set the MasterTableView EditMode to InPlace and have the columns auto generated. The issue i am seeing is when i click the edit button the RadGrid1_ItemCreated Event is fired but none of theobjects coming in are of type GridDataInsertItem and the IsInEditMode property is always false resulting in a grid that only display "No Records to Display". I'm not sure what i'm missing. Any help would be appreciated. My code is below:

ASPX
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeBehind="Default.aspx.vb" Inherits="TelerikGridControlProject._Default" %>
  
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
  
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
   
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" 
                Name="Telerik.Web.UI.Common.Core.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI" 
                Name="Telerik.Web.UI.Common.jQuery.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI" 
                Name="Telerik.Web.UI.Common.jQueryInclude.js">
            </asp:ScriptReference>
        </Scripts>
    </telerik:RadScriptManager>
    <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource" Visible="true">
    <MasterTableView EditMode="InPlace" AutoGenerateColumns="True" Visible="true">
        <Columns>
           <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
        </Columns>
    </MasterTableView>
    </telerik:RadGrid>
   
</asp:Content>


Code Behind:
Imports Telerik.Web.UI
  
Public Class _Default
    Inherits System.Web.UI.Page
    Private _myDataTable As New DataTable
    Private _nameColumn As DataColumn
    Private _myObjectDataSource As ObjectDataSource
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BuildDataTable()
            FillDataTable()
        End If
    End Sub
    
  
    Private Sub FillDataTable()
        Dim dataRow As DataRow
        For i As Integer = 0 To 1
            dataRow = MyDataTable.NewRow()
            dataRow("CIFNUMBER") = 1
            dataRow("CustomerName") = String.Format("Customer {0}", i)
            dataRow("BusinessType") = String.Format("Business {0}", i)
            dataRow("Role") = "Role"
            dataRow("RelationshipToPrimary") = "Spouse"
            dataRow("VotingRights") = i
            dataRow("Scored") = i * 100
            MyDataTable.Rows.Add(dataRow)
        Next
    End Sub
  
    Private Sub BuildDataTable()
        Dim nameList As List(Of String) = New List(Of String)(New String() {"CIFNUMBER", "CustomerName", "BusinessType", "Role", "RelationshipToPrimary", "VotingRights", "Scored"})
  
        For i As Integer = 0 To nameList.Count - 1
            MyDataTable.Columns.Add(i)
            MyDataTable.Columns.Add(nameList(i))
        Next
  
    End Sub
  
    Public Property MyDataTable As DataTable
        Get
            Return _myDataTable
        End Get
        Set(value As DataTable)
            _myDataTable = value
        End Set
    End Property
  
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = MyDataTable
    End Sub
  
    Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
        If (TypeOf e.Item Is GridDataInsertItem AndAlso e.Item.IsInEditMode) Then
            'init insert operation triggered
            Dim myString As String = "NOTHING"
  
        ElseIf (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
            'edit operation triggered
            Dim myString As String = "NOTHING"
        End If
    End Sub
  
End Class

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Sep 2012, 03:30 AM
Hi David,

The issue occurred because you have called 'BuildDataTable()' and 'FillDataTable()' inside 'Not IsPostBack' condition. Either you have to remove the condition or call those methods in NeedDataSource event.

VB:
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
    BuildDataTable()
    FillDataTable()
    RadGrid1.DataSource = MyDataTable
End Sub

Thanks,
Shinu.
0
David
Top achievements
Rank 1
answered on 05 Sep 2012, 11:15 AM
Great that did the trick. Thank you for your help.
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David
Top achievements
Rank 1
Share this question
or