Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have designed inventory module with textbox and web grid. i need add items from textbox to webgrid dynamically.. Please help me..

What I have tried:

View:


@if (Model != null && Model.Count > 0)
{
int j = 0;
foreach (var i in Model)
{



j++;
}
}
Item Name Item Rate Code Item Code Qty Requested
@Html.TextBox("ItemName", null, new { id = "ItemName", @class = "form-control", autocomplete = "off" }) @Html.TextBoxFor(a => a[j].IRateCode, new { id = "RateCode", @class = "form-control", autocomplete = "off" })@Html.TextBoxFor(a => a[j].ItemCode, new { id = "ItemCode", @class = "form-control", autocomplete = "off" }) @Html.TextBoxFor(a => a[j].QtyRequested, new { id = "QtyRequested", @class = "form-control", autocomplete = "off" }) @if (j > 0)
{
Remove
}

<script language="javascript">
$(document).ready(function () {

//1. Add new row
$("#addNew").click(function (e) {
e.preventDefault();
var $tableBody = $("#dataTable");
var $trLast = $tableBody.find("tr:last");
var $trNew = $trLast.clone();

var suffix = $trNew.find(':input:first').attr('name').match(/\d+/);
$trNew.find("td:last").html('Remove');
$.each($trNew.find(':input'), function (i, val) {
// Replaced Name
var oldN = $(this).attr('name');
var newN = oldN.replace('[' + suffix + ']', '[' + (parseInt(suffix) + 1) + ']');
$(this).attr('name', newN);
//Replaced value
var type = $(this).attr('type');
if (type.toLowerCase() == "text") {
$(this).attr('value', '');
}

// If you have another Type then replace with default value
$(this).removeClass("input-validation-error");

});
$trLast.after($trNew);

// Re-assign Validation
var form = $("form")
.removeData("validator")
.removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse(form);
});

// 2. Remove
$('a.remove').live("click", function (e) {
e.preventDefault();
$(this).parent().parent().remove();
});

});
</script>

@* This lines for multi line insert temprary*@
@System.Web.Optimization.Scripts.Render("~/bundles/jquery")
Posted
Updated 5-Aug-16 21:21pm

1 solution

open visual studio 2012 and create a blank new project.
create new ado.net entity data model with demo entities.
 
Share this answer
 

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