|
[Index.cshtml]
@(Html.EJ().Grid<Object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.DataSource)
-------
.Columns(col =>
{
------
})
.ClientSideEvents(eve => { eve.ActionComplete("complete"); })
)
<script type="text/template" id="template">
-----
<td style="text-align: right;">
Ship Country
</td>
<td style="text-align: left">
<select id="ShipCountry" name="ShipCountry"></select>
</td>
</tr>
</table>
</script>
<script type="text/javascript">
var data = @Html.Raw(Json.Encode(ViewBag.dropdata));
function complete(args) {
if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "dialogtemplate") {
$("#Freight").ejNumericTextbox({ value: parseFloat($("#Freight").val()), width: "116px", height: "28px", decimalPlaces: 2 });
$("#ShipCountry").ejDropDownList({
dataSource: data,
fields: {text:"ShipCountry",value:"ShipCountry"},
width: '116px'
});
if (args.requestType == "beginedit") {
$("#OrderID").attr("disabled", "disabled");
$("#ShipCountry").ejDropDownList("setSelectedValue", args.row.children().eq(3).text());
}
}
}
</script>
[Controller.cs]
public class HomeController : Controller
{
List<DropData> data = new List<DropData>();
public ActionResult Index()
{
ViewBag.DataSource = OrderRepository.GetAllRecords().ToList();
data.Add(new DropData("Argentina",12131));
data.Add(new DropData("China",27564));
data.Add(new DropData("Mexico",32365));
data.Add(new DropData("Spain",442324));
data.Add(new DropData("Japan",516434));
ViewBag.dropdata = data;
return View();
}
public class DropData
{
public DropData()
{
}
public DropData(string ShipCountry, int ShipNo)
{
this.ShipCountry = ShipCountry;
this.ShipNo = ShipNo;
}
public string ShipCountry { get; set; }
public int ShipNo { get; set; }
}
}
} |