How do I setup a Webgridview

Kenneth Tillman 1 Reputation point
2021-01-06T16:40:53.287+00:00

I'm using Visual Studio 2017 with Razor and Vb.net in an MVC environment (don't hold me to that, I'm new to the terminology). I have no Idea if I am even in the right forum.

I have a Web screen that I'm creating a row into a SQL Server table. Part of the screen is to enter a code to lookup and display a description from a table not displayed on the screen. The users want to input bunch of these codes and then when the save button is pushed, save the code along with the table row that was also input on the screen.

Everything I've looked at so far, the programmer either already has the Webgridview displayed or they show 200 lines of c# code to create the webcode using HTML...and as usual, programmers don't do documentation, so there is no explanation on any line of code, nor does it describe what files the coding should be put in.

I can't translate c# into vb. It also doesn't help when someone tries to help by asking a question, without providing any software supporting an answer that may or may not ever be provided.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,507 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,193 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yihui Sun-MSFT 801 Reputation points
    2021-01-07T07:58:30.827+00:00

    Hi @Kenneth Tillman ,

    1. Do you want to use WebGird on the view and write code in VB? I wrote an example, you can refer to it.
      1. The example uses the EF framework to process the database.
        2.WebGrid has many properties that can be set. In the example, I only set some properties. You can hover the mouse cursor on the methods, visual studio will gather suggestions for you.
    2. There are indeed many tutorials that use C# to write code.I found a tutorial on MVC 5 with EF 6 in Visual Basic, which can help you.
      1. In addition, you can also click this link to view a detailed explanation of MVC and VB.net.
        2.When you have read the explanations in these two links, you can better understand the examples I provided.
    3. You can use this code converter to convert most of the C# code into VB code.
      DailyMVCDemoVBContext.vb
          Namespace Models  
          Public Class DailyMVCDemoVBContext  
              Inherits DbContext  
      
              ' Your context has been configured to use a 'DailyMVCDemoVB' connection string from your application's   
              ' configuration file (App.config or Web.config). By default, this connection string targets the   
              ' 'DailyMVCDemoVB.DailyMVCDemoVB' database on your LocalDb instance.   
              '   
              ' If you wish to target a different database and/or database provider, modify the 'DailyMVCDemoVB'   
              ' connection string in the application configuration file.  
              Public Sub New()  
                  MyBase.New("name=DailyMVCDemoVBContext")  
              End Sub  
              Public Property TestModels As DbSet(Of TestModel)  
              ' Add a DbSet for each entity type that you want to include in your model. For more information   
              ' on configuring and using a Code First model, see http:'go.microsoft.com/fwlink/?LinkId=390109.  
              ' Public Overridable Property MyEntities() As DbSet(Of MyEntity)  
      
          End Class  
       End Namespace  
      
      TestModel.vb Namespace Models
      Public Class TestModel
      Public Property Id As Integer
      Public Property Content As String
      End Class
      End Namespace
      HomeController.vb Imports DailyMVCDemoVB.Models Public Class HomeController
      Inherits System.Web.Mvc.Controller
      Public db As DailyMVCDemoVBContext = New DailyMVCDemoVBContext()
      Function Index() As ActionResult
      Dim result = db.TestModels.ToList()
      Return View(result)
      End Function
      End Class
      Index.vbhtml @Code
      ViewData("Title") = "Home Page"
      End Code
      @ModelType IEnumerable(Of DailyMVCDemoVB.Models.TestModel)
      @Code
      Dim grid = New WebGrid(Model, canPage:=True, rowsPerPage:=2)
      grid.Pager(WebGridPagerModes.All)
      End Code
      @grid.GetHtml(tableStyle:="table table-bordered",
      headerStyle:="header",
      alternatingRowStyle:="alt", selectedRowStyle:="select",
      columns:=grid.Columns(grid.Column("Id", "Id"), grid.Column("Content", "Content")))
      **Here is the result. **
      54331-8888.gif

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Best Regards,
    YihuiSun

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.