Click here to Skip to main content
15,435,841 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all ,

Im very new to mvc . I have a webgrid in which values are populated using stored procedure. I need to add a dropdownlist in this webgrid in which values are also populated from database.I tried everything on internet. Could anyone help me please.Any help will be really appreciated .Thanks in advance .

What I have tried:

@model  List< RealEstate.Models.SP002_DETAILS_Result >
    Layout = null;
    var grid = new WebGrid(Model, canSort: false, canPage: false);

<div id="gridContent" style=" padding:20px; ">
         tableStyle: "webgrid-table",
         headerStyle: "webgrid-header",
         footerStyle: "webgrid-footer",
         alternatingRowStyle: "webgrid-alternating-row",
         selectedRowStyle: "webgrid-selected-row",
         rowStyle: "webgrid-row-style",
         mode: WebGridPagerModes.All,

                 grid.Column(header: "No.",
    format: item => item.WebGrid.Rows.IndexOf(item) + 1 + Math.Round(Convert.ToDouble(grid.TotalRowCount / grid.PageCount) / grid.RowsPerPage) * grid.RowsPerPage * grid.PageIndex),
        @*grid.Column("Roomid", "ID", format: @<text>  @item.Roomid 
            <label id="UserID" class="edit-mode">@item.Roomid</label> </text>, style: "col1Width"),*@

        grid.Column("Roomname", "Room Name", format: @<text>  
                <label id="lblName">@item.Roomname</label>

                Html.DropDownList(@item.Roomname, @item.getrooms) </ text >, style: "col2Width"),

                @*< input type = "text" id = "Roomname" value = "@item.Roomname" class="edit-mode" /></text>, style: "col2Width"),*@

                grid.Column("Tenantname", "Tenant name", format: @<text>
                            <label id="lblSurName">@item.Tenantname</label>
                        <input type="text" id="Tenantname" value="@item.Tenantname" class="edit-mode" />
                </text>, style: "col2Width"),
                                     grid.Column("tenantrent", "Rent Amnt", format: @<text>
                                            <label id="lbltenantrent">@item.tenantrent</label>
                                        <input type="text" id="tenantrent" value="@item.tenantrent" class="edit-mode" />
                                    </text>, style: "col2Width"),
                                                         grid.Column("tenantunid", "ID", format: @<text>
                                                                <label id="lbltenantunid">@item.tenantunid</label>
                                                            <input type="text" id="tenantunid" value="@item.tenantunid" class="edit-mode" />
                                                        </text>, style: "col2Width"),
                                                                             grid.Column("tenantstartdate", "Start Date", format: @<text>
                                                                                    <label id="lbltenantstartdate">@item.tenantstartdate.ToString("dd-MMM-yyyy")</label>
                                                                                <input type="text" id="Startdate" value="@item.tenantstartdate.ToString("dd-MMM-yyyy")" class="edit-mode" />
                                                                            </text>, style: "col2Width"),
                                                                                                 grid.Column("tenantenddate", "End Date", format: @<text>
                                                                                                        <label id="lbltenantenddate">@item.tenantenddate.ToString("dd-MMM-yyyy")</label>
                                                                                                    <input type="text" id="enddate" value="@item.tenantenddate.ToString("dd-MMM-yyyy")" class="edit-mode" />
                                                                                                </text>, style: "col2Width"),

                                                                                                                     grid.Column("depositmant", "Deposit Amnt", format: @<text>
                                                                                                                            <label id="lbldepositmant">@item.depositmant</label>
                                                                                                                        <input type="text" id="depositmant" value="@item.depositmant" class="edit-mode" />
                                                                                                                    </text>, style: "col2Width"),
                                                                                                                                         grid.Column("remarks", "Remarks", format: @<text>
                                                                                                                                                <label id="lblremarks">@item.remarks</label>
                                                                                                                                            <input type="text" id="remarks" value="@item.remarks" class="edit-mode" />
                                                                                                                                        </text>, style: "col2Width"),
                                                                                                                                                             grid.Column("Action", format: @<text>

                                                                                                                                                                <button class="edit-user display-mode1"><img src="~/Images/Edit.png" width="15" height="15" title="Click here to edit Tenant Details" /></button>

                                                                                                                                                                <button class="save-user edit-mode1"><img src="~/Images/suc.png" width="15" height="15" title="Click here to save Tenant Details" /></button>

                                                                                                                                                                <button class="delete-user delete-mode1"><img src="~/Images/Delete12.png" width="15" height="15" title="Click here to delete Tenant Details" /></button>

                                                                                                                                                                <button class="cancel-user edit-mode1"><img src="~/Images/err.png" width="15" height="15" title="Click here to cancel" /></button>

                                                                                                                                                            </text>, style: "col3Width", canSort: false),

                                                                                                                                                                                 grid.Column(format: @<label id="UserID" style="visibility:hidden;width:5px;">@item.tenantid</label>, style: "col3Width")))

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