Résultat : ASP.NET MultiCheckList DropDown
![]() |
| ASP.NET MultiCheckList DropDown |
Ce blog s'intéresse en particulier aux technologies suivantes :.NET, ASP.NET, C#, VB.NET, MS SQL, JQUERY, CSS ,HTML. Ici je vais essayer d'écrire sur les problèmes que nous rencontrons dans notre travail quotidien en particulier sur les problèmes pour lesquels la réponse est difficile à trouver sur l'Internet, je vais partager avec vous mes solutions et connaissances ... J'espère que ce sera un lieu utile pour vous tous .
![]() |
| ASP.NET MultiCheckList DropDown |
![]() |
| Exemple Angular JS en Asp.net |
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MajEmploye.aspx.cs" Inherits="GestEmployes.MajEmploye" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> <script src="Scripts/jquery-1.8.3.min.js"></script> <script src="script.js"></script> <style> body { background-color:cadetblue; } </style> </head> <body> <div ng-app="myApp"> <div ng-controller="EmpCtrl"> <div style="font-family: Verdana; font-size: 12px; margin-left: auto;margin-right:auto; width:700px; text-align:center"> <table> <tr> <td> <table style="margin-left: auto;margin-right:auto;"> <tr> <td style="text-align: right;">Id : </td> <td> <input type="text" id="txtEmpID" ng-model="EmpID" /> </td> </tr> <tr> <td style="text-align: right;">Nom : </td> <td> <input type="text" id="txtEmpNom" ng-model="EmpNom" /> </td> </tr> <tr> <td style="text-align: right;">Prénom : </td> <td> <input type="text" id="txtEmpPrenom" ng-model="EmpPrenom" /> </td> </tr> <tr> <td style="text-align: center;"> </td> <td> <input type="submit" id="btnSubmit" value="Enregistrer" ng-click="save()" /></td> </tr> </table> </td> <td> <input type="button" id="btnListeEmployes" value="Liste des employés" ng-click="getEmployee()" /> Filtre : <input type="text" ng-model="search" /> <table border="1" style="font-family: Verdana; font-size: 12px; margin-left: auto;margin-right:auto; width:400px; margin-top:5px"> <tr style="background-color:olive;color:white"> <td>ID </td> <td>Nom </td> <td>Prénom </td> </tr> <tr ng-repeat="e in items | filter:search""> <td>{{e.ID}} </td> <td>{{e.Nom}} </td> <td>{{e.Prenom}} </td> </tr> </table> </td> </tr> </table> </div> </div> </div> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data; using System.Data.SqlClient; using System.Web.Script.Services; using System.Collections; using System.Web.Script.Serialization; namespace GestEmployes { /// <summary> /// Summary description for EmpService /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class EmpService : System.Web.Services.WebService { string connection = @"Data Source=ServerName;Initial Catalog=Employe;Integrated Security=SSPI;"; [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string InsertEmploye(string empID, string nom, string prenom) { SqlConnection con = new SqlConnection(connection); SqlCommand cmd; try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = "INSERT INTO Employe(ID,Nom,Prenom) VALUES(@ID,@nom,@prenom)"; cmd.Parameters.AddWithValue("@ID", empID); cmd.Parameters.AddWithValue("@nom", nom); cmd.Parameters.AddWithValue("@prenom", prenom); cmd.ExecuteNonQuery(); return "Employé ajouté avec succés"; } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } } [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<Employe> ListeEmployes() { SqlConnection con = new SqlConnection(connection); SqlCommand cmd; try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = "Select * from employe"; SqlDataReader sdr=cmd.ExecuteReader(); List<Employe> ListEmployes = new List<Employe>(); Employe emp; while (sdr.Read()) { emp = new Employe(); emp.ID = Convert.ToInt32(sdr[0]); emp.Nom = sdr[1].ToString(); emp.Prenom = sdr[2].ToString(); ListEmployes.Add(emp); } sdr.Close(); return ListEmployes; } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace GestEmployes { public class Employe { public int ID; public string Nom; public string Prenom; } }
var app = angular.module('myApp', []); function EmpCtrl($scope,$http) { $scope.getEmployee = function () { var httpRequest = $http({ method: 'POST', url: 'EmpService.asmx/ListeEmployes', data: "{}", }).success(function (data, status) { $scope.items = data.d; }); }; $scope.save = function () { $.ajax({ type: "POST", url: "EmpService.asmx/InsertEmploye", data: "{'empID':'" + $scope.EmpID + "','nom':'" + $scope.EmpNom + "','prenom':'" + $scope.EmpPrenom + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert(msg.d); console.log(msg.d); }, error: function (msg) { alert(msg.d); console.log(msg.d); } }); }; }
RegisterRoutes sur global.asax:void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute("DemoRoute1", "Demo/{year}", "~/demo_routing1.aspx"); routes.MapPageRoute("DemoRoute2", "Demo/{lang}/{year}", "~/demo_routing2.aspx"); }
void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); }
<asp:HyperLink ID="HyperLink1" runat="server" target="_blank" NavigateUrl="~/Demo/2014"> Demo 1 </asp:HyperLink> </br> <asp:HyperLink ID="HyperLink2" runat="server" target="_blank" NavigateUrl="~/Demo/FR/2014"> Demo 2 </asp:HyperLink>
<asp:HyperLink ID="HyperLink4" runat="server" target="_blank" NavigateUrl="<%$RouteUrl:annee=2014,routename=DemoRoute1%>">> Demo 3 </asp:HyperLink> </br> <asp:HyperLink ID="HyperLink5" runat="server" target="_blank" NavigateUrl="<%$RouteUrl:lang=FR,annee=2015,routename=DemoRoute2%>"> Demo 4 </asp:HyperLink>
RouteValueDictionary parameters =
new RouteValueDictionary
{
{"year", "2014" }
};
VirtualPathData vpd =RouteTable.Routes.GetVirtualPath(null, "ExpensesRoute", parameters);
HyperLink6.NavigateUrl = vpd.VirtualPath;
Bundling et Minification sont deux techniques que vous pouvez utiliser dans ASP.NET 4 pour améliorer la performance. Bundling et Minification améliore le temps de chargement en réduisant le nombre de requêtes vers le serveur.
Bundling vous permet de combiner plusieurs JavaScript ou CSS fichiers en un seul package.
Minify réduise le nombre de requêtes HTTP que les navigateurs ont à faire, ce qui réduit la taille des fichiers, et améliorer la performance de l'ensemble du site.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Optimization; namespace Bundles_Minification { public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/js").Include( "~/Scripts/jquery-1.7.1.js")); bundles.Add(new StyleBundle("~/Styles/css").Include("~/Styles/site.css")); } } }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup BundleConfig.RegisterBundles(BundleTable.Bundles); }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="demo.aspx.cs" Inherits="Bundles_Minification.demo" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <asp:PlaceHolder ID="PlaceHolder1" runat="server"> <%: Scripts.Render("~/bundles/js") %> <%: Styles.Render("~/Styles/css") %> </asp:PlaceHolder> </head> <body class="maroonbg"> <form id="form1" runat="server"> <div> Demo utilisation Bundling et Minifiation ASP.NET 4 WebForms </div> </form> </body> </html>
Notes:
Vous devez activer le mode debug sur le web.config et ajouter ces namesspaces:
<system.web> <compilation debug="true" targetFramework="4.5.3" /> <httpRuntime targetFramework="4.5.3" /> <pages> <namespaces> <add namespace="System.Web.Optimization" /> </namespaces> <controls> <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" /> </controls> </pages> </system.web>
Code source : Bundling_Minification_Asp.netVS2012