RadGrid with DynamicDataManager (VB.net)

12 posts, 0 answers
  1. Dave Whiting
    Dave Whiting avatar
    41 posts
    Member since:
    Jan 2007

    Posted 16 Feb 2010 Link to this post

    Hi,

    I would like to use the RadGrid in an ASP.net web page using the DynamicDataManager.  I have tried just registering the RadGrid with the DynamicDataManager but get errors saying that the control is not supported (I know I was being hopeful !).  I then did some digging around and found the class for DynamicRadGrid. This example was in C# but I converted it to the following:~

    Imports System 
    Imports System.Data 
    Imports System.Configuration 
    Imports System.Linq 
    Imports System.Web 
    Imports System.Web.Security 
    Imports System.Web.UI 
    Imports System.Web.UI.HtmlControls 
    Imports System.Web.UI.WebControls 
    Imports System.Web.UI.WebControls.WebParts 
    Imports System.Xml.Linq 
    Imports Telerik.Web.UI 
    Imports System.Collections 
    Imports System.Web.DynamicData 
    Imports System.Collections.Generic 
    Imports System.ComponentModel 
    Imports System.Globalization 
    Imports System.Collections.Specialized 
     
    <ControlValueProperty("DataKeySelectedValue")> _ 
    Public Class DynamicRadGrid 
        Inherits RadGrid 
        Implements IControlParameterTarget 
        Implements IPersistedSelector 
        ' 
        Public Sub New() 
        End Sub 
     
        Private selectedIndex As String = Nothing 
     
        Protected Overloads Overrides Sub OnLoad(ByVal e As EventArgs) 
            If SelectedIndexes.Count > 0 Then 
                selectedIndex = SelectedIndexes(0) 
            End If 
     
            MyBase.OnLoad(e) 
        End Sub 
     
        Protected Overloads Overrides Sub OnDataBound(ByVal e As EventArgs) 
            MyBase.OnDataBound(e) 
     
            If selectedIndex <> Nothing Then 
                Dim item As GridItem = Items(selectedIndex) 
                If Not item Is Nothing Then 
                    item.Selected = True 
                End If 
            Else 
                If Items.Count > 0 Then 
                    Items(0).Selected = True 
                End If 
            End If 
        End Sub 
     
        <Browsable(False)> _ 
        Public ReadOnly Property DataKeySelectedValue() As Object 
            Get 
                If Not Me.DataKey Is Nothing Then 
                    Return Me.DataKey.Value 
                End If 
     
                Return SelectedValue 
            End Get 
        End Property 
     
        Private _dataKey As System.Web.UI.WebControls.DataKey 
        Public Property DataKey() As System.Web.UI.WebControls.DataKey Implements IPersistedSelector.DataKey 
            Get 
                Return _dataKey 
            End Get 
            Set(ByVal value As System.Web.UI.WebControls.DataKey) 
                _dataKey = value 
                If Not _dataKey Is Nothing Then 
                    DirectCast(_dataKey, IStateManager).TrackViewState() 
                End If 
            End Set 
        End Property 
     
        'protected override object SaveControlState() 
        '{ 
        '    return new object[]{ 
        '        base.SaveControlState(), 
        '        _dataKey != null ? ((IStateManager)_dataKey).SaveViewState() : null 
        '    }; 
        '} 
     
        'protected override void LoadControlState(object savedState) 
        '{ 
        '    object[] controlState = (object[])savedState; 
        '    base.LoadControlState(controlState[0]); 
        '    if (_dataKey != null) 
        '    { 
        '        ((IStateManager)_dataKey).LoadViewState(controlState[1]); 
        '    } 
        '} 
     
        Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs) 
            MyBase.OnInit(e) 
     
            AllowAutomaticUpdates = True 
            AllowAutomaticDeletes = True 
     
            Dim metaTable As MetaTable = Me.FindMetaTable() 
     
            Dim list As New List(Of String)() 
            For Each column As MetaColumn In metaTable.PrimaryKeyColumns 
                list.Add(column.Name) 
            Next 
            MasterTableView.DataKeyNames = list.ToArray() 
     
            For Each column As MetaColumn In metaTable.Columns 
                If Not column.Scaffold OrElse column.IsLongString OrElse TypeOf column Is MetaChildrenColumn Then 
                    Continue For 
                End If 
     
                Dim gridColumn As New DynamicGridBoundColumn() 
     
                gridColumn.DataField = column.Name 
                gridColumn.ConvertEmptyStringToNull = column.ConvertEmptyStringToNull 
                gridColumn.DataFormatString = column.DataFormatString 
                gridColumn.UIHint = column.UIHint 
                gridColumn.HtmlEncode = column.HtmlEncode 
                gridColumn.NullDisplayText = column.NullDisplayText 
                gridColumn.ApplyFormatInEditMode = column.ApplyFormatInEditMode 
                gridColumn.HeaderText = column.DisplayName 
     
                MasterTableView.Columns.Add(gridColumn) 
            Next 
        End Sub 
     
        Public Function GetPropertyNameExpression(ByVal columnName As StringAs String Implements IControlParameterTarget.GetPropertyNameExpression 
            Return "DataKeySelectedValue" 
        End Function 
     
        ReadOnly Property Table() As MetaTable Implements IControlParameterTarget.Table 
            Get 
                Return Me.FindMetaTable() 
            End Get 
        End Property 
     
        Public Overridable ReadOnly Property FilteredColumn() As MetaColumn Implements IControlParameterTarget.FilteredColumn 
            Get 
                Return Nothing 
            End Get 
        End Property 
    End Class 
     
    Public Class DynamicGridBoundColumn 
        Inherits GridBoundColumn 
        Private _applyFormatInEditMode As System.Nullable(Of Boolean
        Private _convertEmptyStringToNull As System.Nullable(Of Boolean
        Private _dataField As String 
        Private _dataFormatString As String 
        Private _htmlEncode As Boolean = True 
        Private _nullDisplayText As String 
        Private _column As MetaColumn 
     
        Public Overloads Overrides Sub FillValues(ByVal newValues As IDictionary, ByVal editableItem As GridEditableItem) 
            Dim values As New OrderedDictionary() 
     
            ExtractValuesFromBindableControls(values, editableItem) 
     
            For Each entry As DictionaryEntry In values 
                If Not newValues.Contains(entry.Key) Then 
                    newValues.Add(entry.Key, entry.Value) 
                End If 
            Next 
        End Sub 
     
        Friend Shared Sub ExtractValuesFromBindableControls(ByVal dictionary As IOrderedDictionary, ByVal container As Control) 
            Dim control As IBindableControl = TryCast(container, IBindableControl) 
            If Not control Is Nothing Then 
                control.ExtractValues(dictionary) 
            End If 
            For Each control2 As Control In container.Controls 
                ExtractValuesFromBindableControls(dictionary, control2) 
            Next 
        End Sub 
     
        Public Overloads Overrides Sub InitializeCell(ByVal cell As TableCell, ByVal columnIndex As IntegerByVal inItem As GridItem) 
            If TypeOf inItem Is GridEditableItem Then 
                Dim dynamicControl As New DynamicControl() 
                dynamicControl.DataField = DataField 
     
                Dim isInsert As Boolean = TypeOf inItem Is GridEditFormInsertItem OrElse TypeOf inItem Is GridDataInsertItem 
     
                If isInsert Then 
                    dynamicControl.Mode = DataBoundControlMode.Insert 
                End If 
     
                If inItem.IsInEditMode Then 
                    dynamicControl.Mode = DataBoundControlMode.Edit 
                End If 
     
                dynamicControl.UIHint = UIHint 
                dynamicControl.HtmlEncode = HtmlEncode 
                dynamicControl.DataFormatString = DataFormatString 
                dynamicControl.NullDisplayText = NullDisplayText 
     
                If _convertEmptyStringToNull.HasValue Then 
                    dynamicControl.ConvertEmptyStringToNull = ConvertEmptyStringToNull 
                End If 
     
                If _applyFormatInEditMode.HasValue Then 
                    dynamicControl.ApplyFormatInEditMode = ApplyFormatInEditMode 
                End If 
     
                cell.Controls.Add(dynamicControl) 
            Else 
                MyBase.InitializeCell(cell, columnIndex, inItem) 
            End If 
        End Sub 
     
     
        <Category("Behavior"), DefaultValue(False)> _ 
        Public Overloads Property ConvertEmptyStringToNull() As Boolean 
            Get 
                If Me._convertEmptyStringToNull.HasValue Then 
                    Return Me._convertEmptyStringToNull.Value 
                End If 
                Return False 
            End Get 
            Set(ByVal value As Boolean
                Me._convertEmptyStringToNull = New System.Nullable(Of Boolean)(value) 
            End Set 
        End Property 
     
        <DefaultValue(""), Category("Behavior")> _ 
        Public Overrides Property DataField() As String 
            Get 
                If Not Me._dataField Is Nothing Then 
                    Return Me._dataField 
                End If 
                Dim obj2 As Object = MyBase.ViewState("DataField"
                If not obj2 is Nothing Then 
                    Return DirectCast(obj2, String
                End If 
                Return String.Empty 
            End Get 
            Set(ByVal value As String
                If Not Object.Equals(value, MyBase.ViewState("DataField")) Then 
                    MyBase.ViewState("DataField") = value 
                    Me._dataField = value 
                    Me.OnColumnChanged() 
                End If 
            End Set 
        End Property 
     
        <Category("Data"), DefaultValue("")> _ 
        Public Overrides Property DataFormatString() As String 
            Get 
                Return (If(Me._dataFormatString, String.Empty)) 
            End Get 
            Set(ByVal value As String
                Me._dataFormatString = value 
            End Set 
        End Property 
     
        Private ReadOnly Property Column() As MetaColumn 
            Get 
                If MyBase.DesignMode OrElse (Owner Is NothingThen 
                    Return Nothing 
                End If 
                If Me._column Is Nothing Then 
                    Dim table As MetaTable = Owner.OwnerGrid.FindMetaTable() 
                    If table Is Nothing Then 
                        Throw New InvalidOperationException(""
                    End If 
                    Me._column = table.GetColumn(Me.DataField) 
                End If 
                Return Me._column 
            End Get 
        End Property 
     
        Public Overloads Overrides Property HeaderText() As String 
            Get 
                Dim obj2 As Object = MyBase.ViewState("HeaderText"
                If Not obj2 Is Nothing Then 
                    Return DirectCast(obj2, String
                End If 
                If Not Me.Column Is Nothing Then 
                    Return Me.Column.DisplayName 
                End If 
                Return Me.DataField 
            End Get 
            Set(ByVal value As String
                MyBase.HeaderText = value 
            End Set 
        End Property 
     
        <DefaultValue(True), Category("Behavior")> _ 
        Public Overrides Property HtmlEncode() As Boolean 
            Get 
                Return Me._htmlEncode 
            End Get 
            Set(ByVal value As Boolean
                Me._htmlEncode = value 
            End Set 
        End Property 
     
        <Category("Behavior"), DefaultValue("")> _ 
        Public Property NullDisplayText() As String 
            Get 
                Return (If(Me._nullDisplayText, String.Empty)) 
            End Get 
            Set(ByVal value As String
                Me._nullDisplayText = value 
            End Set 
        End Property 
     
     
        <DefaultValue(""), Category("Behavior")> _ 
        Public Overridable Property UIHint() As String 
            Get 
                Dim obj2 As Object = MyBase.ViewState("UIHint"
                If Not obj2 Is Nothing Then 
                    Return DirectCast(obj2, String
                End If 
                Return String.Empty 
            End Get 
            Set(ByVal value As String
                If Not Object.Equals(value, MyBase.ViewState("UIHint")) Then 
                    MyBase.ViewState("UIHint") = value 
                    Me.OnColumnChanged() 
                End If 
            End Set 
        End Property 
     
        <Category("Behavior"), DefaultValue(False)> _ 
        Public Property ApplyFormatInEditMode() As Boolean 
            Get 
                If Me._applyFormatInEditMode.HasValue Then 
                    Return Me._applyFormatInEditMode.Value 
                End If 
                Return False 
            End Get 
            Set(ByVal value As Boolean
                Me._applyFormatInEditMode = New System.Nullable(Of Boolean)(value) 
            End Set 
        End Property 
     
        Public Overloads Overrides Function Clone() As GridColumn 
            Dim column As New DynamicGridBoundColumn() 
            column.CopyBaseProperties(Me
     
            Return column 
        End Function 
     
        Protected Overloads Overrides Sub CopyBaseProperties(ByVal fromColumn As GridColumn) 
            MyBase.CopyBaseProperties(fromColumn) 
            Dim source As DynamicGridBoundColumn = DirectCast(fromColumn, DynamicGridBoundColumn) 
     
            ConvertEmptyStringToNull = source.ConvertEmptyStringToNull 
            DataFormatString = source.DataFormatString 
            UIHint = source.UIHint 
            HtmlEncode = source.HtmlEncode 
            NullDisplayText = source.NullDisplayText 
            ApplyFormatInEditMode = source.ApplyFormatInEditMode 
        End Sub 
     
    End Class 
     
     


    The control now registers but I get an error in the designer saying httpContext can not be null.  The project builds however, but when I run it the following code in the OnInit method throws an error (Me.FindMetaTable).    
     Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs) 
            MyBase.OnInit(e) 
     
            AllowAutomaticUpdates = True 
            AllowAutomaticDeletes = True 
     
            Dim metaTable As MetaTable = Me.FindMetaTable() 
     


    Would it be possible to have a working VB.net version of this control for using with the DynamicDataManager?


    Regards,

    Mark
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 19 Feb 2010 Link to this post

    Hello Mark,

    Could you please specify which is the mentioned DynamicDataManager? Where did you find the C# code you want to use? 

    All the best,
    Iana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dave Whiting
    Dave Whiting avatar
    41 posts
    Member since:
    Jan 2007

    Posted 19 Feb 2010 Link to this post

    Hi,

    The DynamicDataManager is the default one from the toolbox in Visual Studio.  The C# code was the one from 


    Regards

    Mark
  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 24 Feb 2010 Link to this post

    Hi Mark,

    Can you try using some of the online code converters to convert the C# code?
    You can try using ours here for instance or any other you like.

    Regards,
    Iana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Dave Whiting
    Dave Whiting avatar
    41 posts
    Member since:
    Jan 2007

    Posted 24 Feb 2010 Link to this post

    I've tried that but the code output was not compilable.  I made a few tweaks to the code to get it to compile but still no joy.


  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 01 Mar 2010 Link to this post

    Hello Mark,

    Please find the attached sample and try it on your end. Let me know if it helps and if I missed something out.

    Regards,
    Iana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 16 Apr 2010 Link to this post

    Hello Iana & Mark,

    The code Mark uses stroke me as familiar... :-) i converted it last year also. Recently I had problems integrating the DynamicRadGrid in a new project; this post was most helpfull.

    but... there always is a but...

    RadGrid does not seem to be compatible with Framework 4. To simulate:
    Create a DynamicData project in VS2010. Then convert it to telerik webapp. add some data, ajust the global.asax; run, no problem. ok. Edit the list.aspx, and ADD a radgrid with the same datasource as GridView1 and set some props. Run: ok. Replace GridView1 with a RadGrid, oops! error: Controls of type Telerik.Web.UI.RadGrid are not supported. As soon as the DynamicDataManager1.RegisterControl(RadGrid1) statement is entered, the error starts.

    Then i've tried to use this example. Open it in VS2010, convert to recent Telerik, target the Framework 4 in the compiler, then there is an error in de DynamicDataGrid.vb, line 112...

    So, whats Telerik's view on DynamicData support?  Have a nice weekend... :-)


    Regards,

    Erik


  9. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 19 Apr 2010 Link to this post

    Hello Proovit,

    Please find the attached website with the DynamicRadGrid updated so it works under .NET 4.0.

    Greetings,
    Iana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Tina
    Tina avatar
    7 posts
    Member since:
    Apr 2011

    Posted 21 Apr 2011 Link to this post

    Thank you for this post and thank you for the updated project!  I've been trying to figure out for the last couple of days why the RadGrid wouldn't work.  I didn't put 2 and 2 together with the .NET 4.0 upgrade.  Why isn't this information on the main site so that others can find the RadGrid project for .NET 4.0 and DynamicData?  Why isn't there more information on the main site about DynamicData & Telerik?  I'm currently evaulating this product for use with DynamicData and could use all the information I can get my hands on before advising my company to plunk out $$$ for this product.

    Can anyone provide any insight on this?

    Regards
  11. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 27 Apr 2011 Link to this post

    Hi Erik,

    You can check out this blog post for more information on which controls and how you can use them in a DynamicData project. The sample there provides a customized version of our grid especially prepared for such projects.

    Let me know if this helps.

    Kind regards,
    Iana
    the Telerik team
     

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

     
  12. Salman
    Salman avatar
    2 posts
    Member since:
    Jun 2012

    Posted 08 Jul 2014 in reply to Iana Tsolova Link to this post

    The link is broken. Could you please provide the updated link?
  13. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 08 Jul 2014 in reply to Salman Link to this post

    Hello Salman,

    I think you mean this: http://blogs.telerik.com/aspnet-ajax/posts/10-07-29/radcontrols-for-asp-net-ajax-dynamic-data-update.aspx

    Erik
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017