This is a migrated thread and some comments may be shown as answers.
MVC Grid using VB.net
10 Answers 469 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dheeraj Juvvadi
Top achievements
Rank 1
Dheeraj Juvvadi asked on 24 Feb 2010, 10:52 PM
Please help and let me know what am doing wrong. This is very critical for us to make grid work so we can go head with telerik controls

 
<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage(of IEnumerable(Of Demo.ELIS.MVC.CorpNew))" %>  
 
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">  
    TestIG  
</asp:Content>  
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">  
 
    <h2>TestIG</h2>  
    <%  Html.Telerik().Grid(Model).Name("TestGrid").Columns(Function(col)  
                                                                col.Add(Function(o) o.CorpID).Width(20).Title("CORP ID")  
                                                                col.Add(Function(o) o.CorpName).Width(50).Title("CORP NAME")  
                                                                col.Add(Function(o) o.ExistenceDate).Width(10).Title("DATE")  
                                                            End Function).BindTo(Model).Pageable().Sortable().Filterable().Render()%>  
</asp:Content>  
 
<asp:Content ID="Content3" ContentPlaceHolderID="Menu_new" runat="server">  
</asp:Content>  
 
 
 
 
Controller:
Imports Demo.ELIS.Bussiness  
Imports System.Web.Configuration  
Imports System.Collections.Generic  
Imports Telerik.Web.Mvc  
Imports System.Web.Mvc  
Public Class CorporationsController  
    Inherits System.Web.Mvc.Controller  
 
    Function TestIG() As ActionResult  
        Dim Corp As New CorpNew  
        Dim ACrop As New List(Of CorpNew)  
        Try 
            ACrop = Corp.GetActiveCorp()  
        Catch ex As Exception  
            Throw ex  
        Finally 
            Corp = Nothing 
        End Try 
        ViewData("ACorp") = ACrop  
        Return View()  
    End Function 
End Class 

Model:
Imports System.Collections.Generic  
Imports Demo.ELIS.Bussiness  
Imports System.Web.Configuration  
Imports System.Web.Mvc  
Public Class CorpNew  
    Public CorpID As Integer 
    Public CorpName As String 
    Public LawFirmID As Integer 
    Public ExistenceDate As Date 
    Public ShareType As String 
    Public NumberOfShares As Integer 
 
    Private Corp As New Demo.ELIS.Bussiness.Corporations(WebConfigurationManager.ConnectionStrings("Elis").ToString)  
 
 
    Public Sub New()  
        MyBase.New()  
    End Sub 
    Public Sub New(ByVal Dr As DataRow)  
        Try 
            If Not IsDBNull(Dr("CorpID")) Then 
                Me.CorpID = Dr("CorpID")  
            Else 
                Me.CorpID = 0  
            End If 
            If Not IsDBNull(Dr("CorpName")) Then 
                Me.CorpName = Dr("CorpName")  
            Else 
                Me.CorpName = "" 
            End If 
            If Not IsDBNull(Dr("LawFirmID")) Then 
                Me.LawFirmID = Dr("LawFirmID")  
            Else 
                Me.LawFirmID = 0  
            End If 
            If Not IsDBNull(Dr("ExistenceDate")) Then 
                Me.ExistenceDate = Dr("ExistenceDate")  
            End If 
            If Not IsDBNull(Dr("ShareType")) Then 
                Me.ShareType = Dr("ShareType")  
            Else 
                Me.ShareType = "" 
            End If 
            If Not IsDBNull(Dr("NumberofShares")) Then 
                Me.NumberOfShares = Dr("NumberofShares")  
            Else 
                Me.NumberOfShares = 0  
            End If 
        Catch ex As Exception  
            Throw ex  
        End Try 
    End Sub 
 
    Public Function LoadList(ByVal Ds As DataSet) As List(Of CorpNew)  
        Dim List As New List(Of CorpNew)  
 
        Try 
            For Each row As DataRow In Ds.Tables(0).Rows  
                Dim D As New CorpNew(row)  
                List.Add(D)  
            Next 
            Return List  
        Catch ex As Exception  
            Throw ex  
        End Try 
    End Function 
 
    Public Function GetActiveCorp() As IEnumerable(Of CorpNew)  
        Dim Ds As New DataSet  
        Try 
            Ds = Corp.GetActiveCorp()  
            GetActiveCorp = LoadList(Ds)  
        Catch ex As Exception  
            Throw ex  
        Finally 
            Ds = Nothing 
        End Try 
    End Function 
    Public Function GetAnnulledCorp() As List(Of CorpNew)  
        Dim Ds As New DataSet  
        Try 
            Ds = Corp.GetAnnulledCorp()  
            GetAnnulledCorp = LoadList(Ds)  
        Catch ex As Exception  
            Throw ex  
        Finally 
            Ds = Nothing 
        End Try 
    End Function 
End Class 
 

10 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 25 Feb 2010, 08:08 AM
Hi Dheeraj Juvvadi,

Indeed creating the grid in Visual Basic .NET can be a bit overwhelming due the fact that VB lacks multi line lambdas. Here is a quick code snippet showing how to add grid columns

<%  'declare the grid and enable features
    Dim gridBuilder = Html.Telerik().Grid(Model) _
             .Name("Grid") _
             .Pageable() _
             .Sortable()
     
    'Add grid columns
    gridBuilder.Columns(Function(columns) columns.Add(Function(o) o.OrderID).Width(100))
    gridBuilder.Columns(Function(columns) columns.Add(Function(o) o.OrderDate).Format("{0:dd/MM/yyyy}"))
    gridBuilder.Columns(Function(columns) columns.Add(Function(o) o.ShipCountry).Title("Country"))
    'Render the grid
    gridBuilder.Render()
 %>

I have also attached a working VB.NET MVC application.

Regards,
Atanas Korchev
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.
0
Dheeraj Juvvadi
Top achievements
Rank 1
answered on 26 Feb 2010, 01:05 AM
Thank you Atanas, it was helpfull.

Can you please provide me with the sample of code in VB for ajax binding as am stuck with a internal server error/ error 404. when i try to implement ajaxbinding. Also it would help if you can provide with smaples for custom binding and editing functionalities of gird.

below is what i was trying....
    <%  Html.Telerik().Grid(Model).Name("TestGrid").Columns(Function(col)  
                                                                col.Add(Function(o) o.CorpID).Width(20).Title("CORP ID")  
                                                                col.Add(Function(o) o.CorpName).Width(50).Title("CORP NAME")  
                                                                col.Add(Function(o) o.ExistenceDate).Width(10).Title("DATE")  
                                                            End Function).Ajax(Function(a) a.Action("_TestIG", "Corporations")).Pageable().Sortable().Filterable().Render()%> 
0
Atanas Korchev
Telerik team
answered on 26 Feb 2010, 12:58 PM
Hello Dheeraj Juvvadi,

Make sure the action method specified for ajax binding is decorated with the GridAction attribute and that it uses the GridModel class for model when rendering the view. You can paste your code here (only view and controller) so we can inspect it for any issues.

Regards,
Atanas Korchev
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.
0
Dheeraj Juvvadi
Top achievements
Rank 1
answered on 26 Feb 2010, 01:37 PM
I think am not doing it right in the controller. Please provide me with the sample and also provide the sample for editing/adding row for gird.
controller:
Imports Demo.ELIS.Bussiness  
Imports System.Web.Configuration  
Imports System.Collections.Generic  
Imports Telerik.Web.Mvc  
Imports System.Web.Mvc  
Public Class CorporationsController  
    Inherits System.Web.Mvc.Controller  
 
    '  
    ' GET: /Corporations/  
 
 
 
    Function TestIG() As ActionResult  
        'Dim Corp As New CorpNew  
        'Dim ACrop As New List(Of CorpNew)  
        'Try  
        '    ACrop = Corp.GetActiveCorp()  
        'Catch ex As Exception  
        '    Throw ex  
        'Finally  
        '    Corp = Nothing  
        'End Try  
        ''ViewData("ACorp") = ACrop  
        'Return View(ACrop)  
        Return view()  
    End Function 
   
    <GridAction()> _  
    Public Function _AjaxBinding() As ActionResult  
        Dim Corp As New CorpNew  
        Dim ACrop As List(Of CorpNew)  
        Dim GM As New GridModel(Of CorpNew)  
        Try 
            'ACrop = Corp.GetActiveCorp()  
            GM = Corp.GetActiveCorp()  
        Catch ex As Exception  
            Throw ex  
        Finally 
            Corp = Nothing 
        End Try 
        Return View(GM)  
 
        'Return View(New GridModel(Of CorpNew)())  
    End Function 
End Class 
 
 

view:
 
    <%  Html.Telerik().Grid(Model).Name("TestGrid").Columns(Function(col)  
                                                                col.Add(Function(o) o.CorpID).Width(20).Title("CORP ID")  
                                                                col.Add(Function(o) o.CorpName).Width(50).Title("CORP NAME")  
                                                                col.Add(Function(o) o.ExistenceDate).Width(10).Title("DATE")  
                                                            End Function).Ajax(Function(a) a.Action("_AjaxBinding""Corporations")).Pageable().Sortable().Filterable().Render()%> 
0
Atanas Korchev
Telerik team
answered on 26 Feb 2010, 01:45 PM
Hi Dheeraj Juvvadi,

I think the GridModel object is not populated at all not to mention that I am not sure this statement will even compile:

GM = Corp.GetActiveCorp()

If GetActiveCorp() returns a list of CorpNew objects I suggest you try this:

<GridAction()> _  
Public Function _AjaxBinding() As ActionResult  
    Dim ACrop As List(Of CorpNew)  
    Try
        ACrop = Corp.GetActiveCorp()  
    Catch ex As Exception  
        Throw ex  
    Finally
        Corp = Nothing
    End Try
    Return View(New GridModel(ACrop))  
End Function

If this does not help I suggest you try stepping into the _AjaxBinding method with the debugger.

For editing example I suggest you check this one. I think the code is very easy to convert to VB.NET.

Regards,
Atanas Korchev
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.
0
Dheeraj Juvvadi
Top achievements
Rank 1
answered on 26 Feb 2010, 02:04 PM
well, sorry for providing you with a wrong controller sample code. I was trying with different combinations and ended with that. I guess i tryed with what you show above, but will try once again and get back to you. Once again thanks for your help! i really appreciate it.
0
Rodolfo Gonzalez
Top achievements
Rank 1
answered on 08 Apr 2010, 12:45 AM
Btw, on this post I wrote how one can use the column.template function in VB 2008 (which doesn't support lambdas that don't return values like VB 2010).
0
Jigar
Top achievements
Rank 1
answered on 30 Jul 2010, 05:25 PM
Hi There,

I am facing the similar kind of problem;
View:
<%
Dim transGrid = Html.Telerik().Grid(Of City).Name("City").Pageable(Function(p)  p.PageSize(10).Sortable().Scrollable().Filterable().Groupable().Footer(True)
      
        transGrid.DataKeys(Function(key) key.Add(Function(c) c.id))
        transGrid.Columns(Function(columns) columns.Bound(Function(c) c.id).Title("Id")
        transGrid.Columns(Function(columns) columns.Bound(Function(c) c.name).Title("Name")
       transGrid.DataBinding(Function(dataBind) dataBind.Ajax().Select("_Index", "City") _
                                                                    .Insert("Create", "City") _
                                                                    .Update("Edit", "City") _
                                                                    .Delete("Delete", "City") _
                                                                    )
      transGrid.Render()
%>

Controller:
      <GridAction()> _
        Function _Index() As ActionResult
            'Dim _Cities = _repository.ListAll()
            Dim _gridCity = New GridModel(Of CTS_CityMaster)
            _gridCity = _repository.ListAll()
            Return View(_gridCity)
        End Function

If I pass model like Html.Telerik().Grid(Model); i can see the data in grid but the way i mentioned above I am not able to see the data in grid. I tried to put debug poing at _Index function; but this "Function _Index() As ActionResult" never get called.

Can anybody please help me with this?

thanks in advance.

0
turkush .
Top achievements
Rank 1
answered on 13 Jun 2011, 01:54 PM
Hi,

I tried the same solution, my grouping is not working.

<%

 

= Html.Telerik().Grid(Model)

 

 

.Name(

 

"Grid")

 

.HtmlAttributes(

 

new { @class = "Vista"})

 

 

.Columns(columns =>

 

{

 

columns.Bound(o => o.title).Width(100);

 

columns.Bound(o => o.Director).Width(200);

 

columns.Bound(o => o.ReleaseDate).Format(

 

"{0:MM/dd/yyyy}").Width(120);

 

 

})

.DataBinding(dataBinding => dataBinding.Ajax().Select(

 

"Index", "Home"))

 

 

.Sortable()

 

.Scrollable(scrolling => scrolling.Enabled(

 

true))

 

 

.Groupable(grouping => grouping.Enabled(

 

true))

 

 

%>

Added in site.master:

 

 

<% Html.Telerik().ScriptRegistrar().DefaultGroup(group => group

 

.Add(

 

 

"jquery-1.4.4.min.js")

 

 

.Add(

 

 

"jquery.validate.min.js")

 

 

.Add(

 

 

"telerik.window.min.js")

 

 

.Add(

 

 

"telerik.textbox.min.js")

 

 

.Add(

 

 

"telerik.draganddrop.min.js")

 

 

.Add(

 

 

"telerik.datepicker.min.js")

 

 

.Add(

 

 

"telerik.calendar.min.js")

 

 

.Add(

 

 

"telerik.common.js")

 

 

.Add(

 

 

"telerik.grid.js")

 

 

.Add(

 

 

"telerik.grid.filtering.js")

 

 

.Add(

 

 

"telerik.grid.editing.js")

 

 

.Add(

 

 

"telerik.grid.grouping.js")

 

 

.Add(

 

 

"telerik.grid.reordering.js")

 

 

.Add(

 

 

"telerik.grid.resizing")); %>

WHATS WRONG WITH THIS??

Thanks

 

0
turkush .
Top achievements
Rank 1
answered on 13 Jun 2011, 01:56 PM
Hi,

I tried the same solution, my grouping is not working.
<%= Html.Telerik().Grid(Model)
                                 .Name("Grid")
                                 .HtmlAttributes(new { @class = "Vista"})
                                 .Columns(columns =>
                                 {
                                     columns.Bound(o => o.title).Width(100);
                                     columns.Bound(o => o.Director).Width(200);
                                     columns.Bound(o => o.ReleaseDate).Format("{0:MM/dd/yyyy}").Width(120);
  
                                 })
                                    .DataBinding(dataBinding => dataBinding.Ajax().Select("Index", "Home"))
                                    .Sortable()
                                    .Scrollable(scrolling => scrolling.Enabled(true))
                                    .Groupable(grouping => grouping.Enabled(true))
    %>
 i added in site.master following script:
<% Html.Telerik().ScriptRegistrar().DefaultGroup(group => group
                                                          .Add("jquery-1.4.4.min.js")
                                                          .Add("jquery.validate.min.js")
                                                          .Add("telerik.window.min.js")
                                                          .Add("telerik.textbox.min.js")
                                                          .Add("telerik.draganddrop.min.js")
                                                          .Add("telerik.datepicker.min.js")
                                                          .Add("telerik.calendar.min.js")
                                                          .Add("telerik.common.js") 
                                                          .Add("telerik.grid.js") 
                                                          .Add("telerik.grid.filtering.js") 
                                                          .Add("telerik.grid.editing.js") 
                                                          .Add("telerik.grid.grouping.js") 
                                                          .Add("telerik.grid.reordering.js")
                                                          .Add("telerik.grid.resizing")); %>


 

 

 

Tags
Grid
Asked by
Dheeraj Juvvadi
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Dheeraj Juvvadi
Top achievements
Rank 1
Rodolfo Gonzalez
Top achievements
Rank 1
Jigar
Top achievements
Rank 1
turkush .
Top achievements
Rank 1
Share this question
or