General
This is a video in Channel 9 at dotnetConf 2016.
Skill 1
GridView Control
- Use
ItemTypeto use object easily (for each field, get code hint as object’s property) - Use
OnCallingDataMethodsto bindDataMethodObject
GridView aspx page:
<asp:GridView runat="server"
OnCallingDataMethods="grid_CallingDataMethods"
ItemType="ModernizeWebForms2015.Models.Trip"
SelectMethod="Get">
</asp:GridView>
Code behind file:
protected void grid_CallingDataMethods(object sender, CallingDataMethodsEventArgs e)
{
e.DataMethodsObject = _Repo;
}
Skill 2
Could modify at page DOM inspector then save modify back to Visual Studio (IE).
Skill 3
[WebMethod] ASP.NET Web Forms JavaScript AJAX method.
aspx file:
<asp:ScriptManager runat="server" EnablePageMethods="true"></asp:ScriptManager>
<script type="text/javascript">
(function() {
var myController = function($scope, $http) {
$scope.orderByField = "ID";
$scope.orderByAsc = false;
PageMethods.grid_GetData(function (result, context) {
console.log(result);
$scope.trips = result;
$scope.$apply();
});
};
})();
</script>
Code behind file:
// The return type can be changed to IEnumerable, however to support
// paging and sorting, the following parameters must be added:
// int maximumRows
// int startRowIndex
// out int totalRowCount
// string sortByExpression
[WebMethod()]
public static IEnumerable<Models.Trip> grid_GetData()
{
Models.TripRepository _Repo = new Models.TripRepository();
return _Repo.Get().ToList();
}