String[] _cities = { "London", "New Delhi" }; var _customers = new[] { new { Name = "Saurabh", City = "London" }, new { Name = "Sumit", City = "New Delhi" }, new { Name = "Rohit", City = "London" }, new { Name = "Rahul", City = "Mumbai" }, new { Name = "Suresh", City = "London" }, new { Name = "Sunil", City = "New Delhi" }, new { Name = "Mahesh", City = "Agra" } }; var _query = from c in _customers where (_cities).Contains(c.City) select c;
Friday, April 25, 2014
Find Customer list whom city exists in city array
Tuesday, September 25, 2012
Select text, value, remove, selecteIndex on select element
1. Add options to the end of a select $("#drpCountry").append(''); $("#drpCountry").append(''); or $('').appendTo($("#drpCountry")); $('').appendTo($("#drpCountry")); 2. Add options to the start of a select $("#drpCountry").prepend(''); 3. Replace all the options with new options $("#drpCountry").html(''); 4. Replace items at a certain index $("#drpCountry option:eq(1)").replaceWith(''); $("#drpCountry option:eq(2)").replaceWith(''); 5. Set the element at index 2 to be selected $("#drpCountry option:eq(2)").attr("selected", "selected"); 6. Set the selected element by text $("#drpCountry").val("India").attr("selected", "selected"); 7. Set the selected element by value $("#drpCountry").val("2"); 8. Remove an item at a particular index $("#drpCountry option:eq(0)").remove(); 9. Remove first item $("#drpCountry option:first").remove(); 10. Remove last item $("#drpCountry option:last").remove(); 11. Get the text of the selected item var selectedtext=$("#drpCountry option:selected").text(); 12. Get the value of the selected item var selectedvalue=$("#drpCountry option:selected").val(); 13. Get the index of the selected item var selectedIndex=$("#drpCountry option").index($("#drpCountry option:selected")); 14. Alternative way to get the selected item var selectedItem=$("#drpCountry option:selected").prevAll().size(); 15. Insert an item in after a particular position $("#drpCountry option:eq(0)").after(""); 16. Insert an item in before a particular position $("#drpCountry option:eq(3)").before(""); 17. Getting values when item is selected $("#drpCountry").change(function() { var Selectedvalue=$(this).val(); var Selectedtext=$(this).children("option:selected").text(); });
Saturday, December 10, 2011
Fading image using jquery FadeTo
<script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script> <script> window.setInterval("Method()", 1000); Method = function () { var ff = parseFloat($("img").css("opacity")).toFixed(1); // alert(ff); if (ff == 0.6) $("img").fadeTo("slow", 1); else $("img").fadeTo("slow", 0.6); }; </script> <img border="0" src="Images/Bald.jpg" width="400" />
Tuesday, December 6, 2011
Populate Select from ajax with jquery
<head> <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script> <script> $(document).ready(function () { $.ajax({ url: "Fetchdata.ashx", type: "GET", dataType : 'json', success: function (msg) { $("#ddlcity").get(0).options.length = 0; $("#ddlcity").get(0).options[0] = new Option("Select City", "-1"); $.each(msg, function (k, v) { //alert(v); $("#ddlcity").get(0).options[$("#ddlcity").get(0).options.length] = new Option(v.Name, v.ID); }); }, error: function (msg) { alert("Error !!!!"); } }); }); </script> </head> <body> <select id="ddlcity"></select> </body>
<%@ WebHandler Language="C#" Class="Fetchdata" %> using System; using System.Web; using System.Collections.Generic; public class Fetchdata : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; List Objcity = GetList(); System.Web.Script.Serialization.JavaScriptSerializer objJs = new System.Web.Script.Serialization.JavaScriptSerializer(); context.Response.Write( objJs.Serialize(Objcity)); } public bool IsReusable { get { return false; } } public List GetList() { List <Citydata> item = new List<Citydata>(); item.Add(new Citydata() { Name = "Delhi", Id = "1" }); item.Add(new Citydata() { Name = "Mumbai", Id = "2" }); item.Add(new Citydata() { Name = "Kolcatta", Id = "3" }); item.Add(new Citydata() { Name = "Chennai", Id = "4" }); item.Add(new Citydata() { Name = "Banglore", Id = "5" }); item.Add(new Citydata() { Name = "Agra", Id = "6" }); return item; } } public class Citydata { string _Name = string.Empty; public string Name { get { return _Name; } set { _Name = value; } } string _Id = string.Empty; public string Id { get { return _Id; } set { _Id = value; } } }
Tags
AJAX
,
Asp.net
,
C#
,
DropDownList
,
JavaScript
,
jquery
Monday, November 7, 2011
server side validation using regular expression and extension method
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace DAL { public static class Extention { const string MatchEmailPattern = @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]? [0-9]{1,2}|25[0-5]|2[0-4][0-9])\." + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]? [0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$"; const string NumberPattern=@"^\d$"; const string AlphbetPattern = @"^[a-zA-Z]*$"; const string AlphanumricPattern = @"^[a-zA-Z0-9]*$"; const string AlphNumeric_space = @"[^\w\s]"; const string AlphaNumeric_spacial = @"^((?:[A-Za-z0-9-'.,@:?!()$#/\\]+|&[^#])*&?)$"; const string AlphaNumeric_Hyphen = @"^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$"; //Date Constant///////////////// const string Dateyyyydddmm_pattern = @"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$"; const string Datemmddyyyy_Pattern = @"^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d$"; const string Dateddmmyyyy_Pattern = @"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"; const string DateddMMMyyyy_Pattern = @"^(0[1-9]|1[012])[- /.](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[- /.](19|20)\d\d$"; const string Url_Pattern=@"((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])"; public static bool IsEmail(this string value) { if (value != null) return System.Text.RegularExpressions.Regex.IsMatch(value, MatchEmailPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsNumber(this string value) { if (value != string.Empty) return System.Text.RegularExpressions.Regex.IsMatch(value, NumberPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsAlphabet(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, AlphbetPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsAlphaNumeric(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, AlphanumricPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsAlphaNumeric_Space(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, AlphNumeric_space, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsAlphaNumeric_Spacial(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, AlphaNumeric_spacial, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsAlphaNumeric_Hyphen(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, AlphaNumeric_Hyphen, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsDateyyyydddmm(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, Dateyyyydddmm_pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsDatemmddyyyy(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, Datemmddyyyy_Pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsDateddmmyyyy(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, Dateddmmyyyy_Pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsDateddMMMyyyy(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, DateddMMMyyyy_Pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } public static bool IsUrl_Valid(this string value) { if (!string.IsNullOrEmpty(value)) return System.Text.RegularExpressions.Regex.IsMatch(value, Url_Pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase); else return false; } } }
Tags
asp
,
C#
,
Regex
,
RegularExpression
,
Server side validation
,
Validation
Saturday, October 1, 2011
custom paging in datagrid-repeater-gridview
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
using System; using System.Text; using System.Collections.Generic; using System.Linq; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int totalRecords = 234; int pageSize = 10; int totalPages = totalRecords / pageSize + (totalRecords % pageSize > 0 ? 1 : 0); int NoofNumaricLink = 7; int currentPage = 1; if (Request.QueryString["page"] == null) currentPage = 1; if (Request.QueryString["page"] != null) { if (!int.TryParse(Request.QueryString["page"].ToString(), out currentPage)) currentPage = 1; if (currentPage > totalPages) currentPage = totalPages; } List <Customer> customers =(new Customer()).GetCustomerList(); var ObjCustomerslist = customers.Skip((currentPage - 1)*pageSize).Take(pageSize); Dgpager.DataSource = ObjCustomerslist; Dgpager.DataBind(); litPaging.Text = CreatePageLinks(totalRecords, pageSize, totalPages, NoofNumaricLink,currentPage); } string CreatePageLinks(int totalRecords, int pageSize, int totalPages, int TotalNoLink, int currentPage) { if (totalRecords <= pageSize) return ""; StringBuilder strPager = new StringBuilder(); string pageUrl = Context.Request.Url.AbsolutePath; if (currentPage > 1) { strPager.Append(string.Format("Fist", 1, pageUrl)); strPager.Append(string.Format("Previous", (currentPage - 2) + 1, pageUrl)); } if(!(currentPage > 1)) { strPager.Append("FirstPrevious"); } int min, max; if (TotalNoLink >= totalPages) { min = 1; max = totalPages; } else { if (currentPage - TotalNoLink / 2 > 0) max = (currentPage + TotalNoLink / 2 - (TotalNoLink - 1) % 2); else max = TotalNoLink; if (max > totalPages) max = totalPages; min = max - TotalNoLink + 1 > 0 ? max - TotalNoLink + 1 : 1; } for (int n = min; n <= max; n++) { if (n > totalPages) break; if (n == currentPage) strPager.Append(String.Format(" {0}", n.ToString())); else strPager.Append(String.Format("{0} ", n, (n - 1) + 1,pageUrl)); } if (currentPage < totalPages) { strPager.Append(String.Format("Next ", currentPage + 1, pageUrl)); strPager.Append(String.Format("Last ", totalPages, pageUrl)); } if (!(currentPage < totalPages)) { strPager.Append("NextLast"); } return strPager.ToString(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Customer { string uid = string.Empty; public string Uid { get { return uid; } set { uid = value; } } string name = string.Empty; public string Name { get { return name; } set { name = value; } } int age = 0; public int Age { get { return age; } set { age = value; } } public List <Customer> GetCustomerList() { List <Customer> listitem = new List <Customer>(); for (int n = 1; n < 245; n++) { listitem.Add(new Customer() { Uid = n.ToString(), Name = "name" + n.ToString(), Age = n * 10 }); } return listitem; } }
Tuesday, September 27, 2011
Google like Paging in Asp.net
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Security.Cryptography; using System.Text; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int totalRecords = 234; int pageSize = 10; int totalPages = totalRecords / pageSize + (totalRecords % pageSize > 0 ? 1 : 0); int NoofNumaricLink = 7; litPaging.Text = CreatePageLinks(totalRecords, pageSize, totalPages, NoofNumaricLink); } string CreatePageLinks(int totalRecords, int pageSize,int totalPages, int TotalNoLink) { if (totalRecords <= pageSize) return ""; StringBuilder strPager = new StringBuilder(); int currentPage = 1; string pageUrl = Context.Request.Url.AbsolutePath; if (Request.QueryString["page"] == null) currentPage = 1; if (Request.QueryString["page"] != null) { if (!int.TryParse(Request.QueryString["page"].ToString(), out currentPage)) currentPage = 1; if (currentPage > totalPages) currentPage = totalPages; } if (currentPage > 1) strPager.Append(string.Format("Previous", (currentPage - 2) + 1, pageUrl)); int min, max; if (TotalNoLink >= totalPages) { min = 1; max = totalPages; } else { if (currentPage - TotalNoLink / 2 > 0) max = (currentPage + TotalNoLink / 2 - (TotalNoLink - 1) % 2); else max = TotalNoLink; if (max > totalPages) max = totalPages; min = max - TotalNoLink + 1 > 0 ? max - TotalNoLink + 1 : 1; } for (int n = min; n <= max; n++) { if (n > totalPages) break; if (n == currentPage) strPager.Append(String.Format(" {0}", n.ToString())); else strPager.Append(String.Format("{0} ", n, (n - 1) + 1,pageUrl)); } if (currentPage < totalPages) strPager.Append(String.Format("Next ", currentPage+1,pageUrl)); return strPager.ToString(); } }
Subscribe to:
Posts
(
Atom
)