Click here to Skip to main content
15,312,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a controller that is creating some columns for my WebGrid based on the names of some fields. For example, I have a field that is titled "e_qty", and the "e_" means that it should end up being an editable field. So the function is there that creates the textbox columns for the WebGrid if needed (it works fine). I'm passing the datatable as a list of objects to the View. Normally this will populate my WebGrid with all the values just fine. It's when I have textboxes in my WebGrid that it doesn't add the actual values. I can set the "value" property of the textboxes in the controller, but that defeats the purpose of sending the list of objects to the view. So the question is: Can you use a model to populate a WebGrid that has textboxes without having to set the "value" property? I'm just wanting to know if what I'm trying to do is possible.

Here is how I'm bringing the model over from the controller and filling the WebGrid:

@ModelType System.Collections.Generic.IEnumerable(Of Object)
    Layout = "~/Views/Shared/_VisualRuleLayout.vbhtml"
End Code

<link href="~/Content/bootstrap.css" rel="stylesheet" />

@Using Html.BeginForm("Cancel", "GridView", FormMethod.Post)
        <div Class="form-horizontal">

                    Dim grid = New WebGrid(Model, canPage:=True, canSort:=True, rowsPerPage:=50)
            End Code

                    @grid.GetHtml(htmlAttributes:=New With {
                        .id = "grid",
                        .class = "table table-bordered table-striped table-condensed",
                        .name = "grid1"},
                        emptyRowCellValue:="No Records Found",
                End Code

What I have tried:

I've tried setting the WebGrid's cells back to just plain cells and that works, but I need the editable columns to show as textboxes with the cell's value already populated in it.

I've also tried setting the e_ columns to have hidden textboxes hoping that once the edit button is clicked, the textbox can be unhidden and the value will be set to it's "value" property. But this didn't work because the original value from the model still did not fill the WebGrid cell because of the hidden textbox.
Updated 1-Aug-19 3:39am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900