Private: MY Note

Every thing you imagine, Study it, know it, use it!

Test Your Level with British Council

http://english-for-thais.blogspot.com/2008/09/352-bangkok-post.html

อ่านBangkok Postให้รู้เรื่องเหมือนอ่าน ไทยรัฐ

++++++++++++++++++++++++++++++++++++++

Online English tests are fun and can give an indication of your ability.
When you finish each of these tests, your scores will be reported in terms of a broad scale: elementary to upper intermediate.

http://www.britishcouncil.org/learnenglish-central-test-test-your-level.htm

++++++++++++++++++++++++++++++++++++++

ศสษ = ศูนย์พัฒนาความสามารถในการใช้ภาษาอังกฤษ
http://www.eldc.go.th

เกมส์ : http://www.eldc.go.th/FlashGame1/page/index.jsp

รายการวิทยุ : http://www.eldc.go.th/eldc3/page/radio/index.jsp

July 9, 2009 Posted by dev1 | Learn English | | No Comments Yet

Use explicit casting instead of DataBinder.Eval

The DataBinder.Eval method uses .NET reflection to evaluate the arguments that are passed in and to return the results. Consider limiting the use of DataBinder.Eval during data binding operations in order to improve ASP.NET page performance.

Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:

<ItemTemplate>

<tr>

<td><%# DataBinder.Eval(Container.DataItem, “field1″) %></td>

<td><%# DataBinder.Eval(Container.DataItem, “field2″) %></td>

</tr>

</ItemTemplate>

Using explicit casting offers better performance by avoiding the cost of .NET reflection. Cast the Container.DataItem as a DataRowView:

<ItemTemplate>

<tr>

<td><%# ((DataRowView)Container.DataItem)["field1"] %></td>

<td><%# ((DataRowView)Container.DataItem)["field2"] %></td>

</tr>

</ItemTemplate>

2/12/2008

June 26, 2009 Posted by dev1 | ASP.NET 3.0 | | No Comments Yet

Define css, js from code behide

1 protected void Page_Load(object sender, EventArgs e)
2 {
3 LabelSaveStatus.Text = “”;
4 if (!IsPostBack)
5 {
6 HtmlHead head = (HtmlHead)Page.Header;
7
8 HtmlLink link = new HtmlLink();
9 link.Attributes.Add(href, Page.ResolveClientUrl(http://yui.yahooapis.com/2.5.2/build/fonts/fonts-min.css));
10 link.Attributes.Add(type, text/css);
11 link.Attributes.Add(rel, stylesheet);
12 head.Controls.Add(link);

June 22, 2009 Posted by dev1 | ASP.NET | | 1 Comment

Generics List.FindAll (to filter)

Since 2.0, generics were one of my favorites. Use them quite a bit in my object models. And with that comes the need for iterative operations. One such being using FindAll to get filtered results using some sort of criteria. While generic predicates is one way to do it (for well defined filters), I also use anonymous delegate to do filtering dynamically (like based on name, for example). Let’s look at either one.

Say we have a Product class and we get a List as available products to be shown to the user. Say we have an attribute (enumeration) for each product that determines its category. In a simple scenario, I have a well defined set of limited categories and I define predicates to do the filtering. And for some dynamic filtering, I’m using anonymous delegate to do the filtering. Take a look:

/// <summary>

/// An example to show generic predicates

/// </summary>

[Serializable]

public class myProduct

{

/// <summary>

/// ProductCategory

/// </summary>

public enum ProductCategory

{

General = 1,

Speciality = 2

}

private string _Name = string.Empty,

_ProductID = string.Empty;

private ProductCategory _Category;

public string Name

{

get { return _Name; }

set { _Name = value; }

}

public string ProductID

{

get { return _ProductID; }

set { _ProductID = value; }

}

public ProductCategory Category

{

get { return _Category; }

set { _Category = value; }

}

public myProduct() { }

#region “Predicate for Filters”

/// <summary>

/// Predicate for General Products

/// </summary>

/// <param></param>

/// <returns></returns>

private static bool GeneralProducts(myProduct p)

{

return (p.Category == myProduct.ProductCategory.General);

}

/// <summary>

/// Predicate for Speciality Products

/// </summary>

/// <param></param>

/// <returns></returns>

private static bool SpecialityProducts(myProduct p)

{

return (p.Category == myProduct.ProductCategory.Speciality);

}

/// <summary>

/// Filter and return General Products

/// </summary>

/// <param></param>

/// <returns></returns>

public static List<myProduct> GetGeneralProducts(List<myProduct> productList)

{

return productList.FindAll(GeneralProducts);

}

/// <summary>

/// Filter and return Speciality Products

/// </summary>

/// <param></param>

/// <returns></returns>

public static List<myProduct> GetSpecialityProducts(List<myProduct> productList)

{

return productList.FindAll(SpecialityProducts);

}

#endregion “Predicate for Filters”

/// <summary>

/// Anonymous delegate to filter

/// </summary>

/// <param></param>

/// <param></param>

/// <returns></returns>

public static List<myProduct> GetProductsNamedLike(List<myProduct> productList, string nameLike)

{

return productList.FindAll(delegate(myProduct p) { return p.Name.Contains(nameLike); });

}

}
We will find a lot of discussion and explanation about this topic, but this is my simplified case to show the usage.

Love coding!

June 15, 2009 Posted by dev1 | .NET, .NET 2.0, ASP.NET, ASP.NET 3.0 | | No Comments Yet

JavaScript : Ignore Case Array Sort

When you sort an array in Javascript the array gets sorted into dictionary order. This means that ‘A’ is less than ‘a’ and gets sorted that way. If your array consists of both uppercase and lowercase entries then you probably want to sort alphabetically ignoring the case of the individual entries instead. We can change the way that the array sort method works by passing it a parameter identifying a function that contains the instructions on how to compare the entries.

To sort an array into order ignoring case add the following code (into the head section of your page is probably the most appropriate place):

function charOrdA(a, b){
a = a.toLowerCase(); b = b.toLowerCase();
if (a>b) return 1;
if (a <b) return -1;
return 0; }
function charOrdD(a, b)
a = a.toLowerCase(); b = b.toLowerCase();
if (a<b) return 1;
if (a >b) return -1;
return 0; }

We can now sort the array without the upper and lower case entries being sorted into different orders. The following example shows how:

charArray = new Array(’c',’A',’z',’f',’D');
charArray.sort( charOrdA );
document.write(’Ascending : ‘ + charArray + ‘<br />’);
charArray.sort( charOrdD );
document.write(’Descending : ‘ + charArray + ‘<br />’);

June 15, 2009 Posted by dev1 | JAVASCRIPT | | No Comments Yet

Creating Tricker when Insert Update

– ================================================
– Template generated from Template Explorer using:
– Create Trigger (New Menu).SQL

– Use the Specify Values for Template Parameters
– command (Ctrl-Shift-M) to fill in the parameter
– values below.

– See additional Create Trigger templates for more
– examples of different Trigger statements.

– This block of comments will not be included in
– the definition of the function.
– ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
– =============================================
– Author:        <Author,,Name>
– Create date: <Create Date,,>
– Description:    <Description,,>
– =============================================
CREATE TRIGGER BW_POI_SetCountryID
ON  BW_POI
AFTER INSERT,UPDATE
AS
BEGIN
SET NOCOUNT ON;

update bw_poi
set countryid = case
when i.country = ‘us’ or i.country = ‘usa’ or i.country like ‘united states%’ then 0
when i.country = ‘canada’ then 1
when i.country = ‘mexico’ or i.country = ‘mx’ then 2
when i.country = ‘australia’ then 3
when i.country = ‘thailand ‘ then 4
else null
end
from inserted i
inner join bw_poi p on i.[id] = p.[id]

END
GO

**************************select country, countryid, *
from bw_poi
where countryid is null and country <> ”

–update bw_poi set country = country

May 15, 2009 Posted by dev1 | sql server 2005 | | No Comments Yet

How do I convert an Enum value to a String?

I have an enum SortFilter, which looks like following:

public enum SortFilter

{

FirstName,

LastName,

Age,

Experience

}

Now, let’s say I want to display the string value of enum in some control. For that, I will have to convert Enum value to string. For example, I want to add all enum string values to a DropDownList. The following code loops through the enumeration and adds string values to it. Here SortByList is DropDownList.

SortByList.Items.Clear();

// Conversion from Enum to String

foreach (string item in Enum.GetNames(typeof(ArrayListBinding.SortFilter)))

{

SortByList.Items.Add(item);
}

This code converts an enum to string:

string name= Enum.GetName(typeof(ArrayListBinding.SortFilter), SortFilter.FirstName);

Now let’s say, you have an enum string value say, “FirstName” and now you want to convert it to Enum value. The following code converts from a string to enum value, where Developer.SortingBy is of type SortFilter enumeration:

// Conversion from String to Enum

Developer.SortingBy = (SortFilter)Enum.Parse(typeof(SortFilter), “FirstName”);

January 27, 2009 Posted by dev1 | .NET | | 1 Comment

The components required to enumerate web references are not installed on this computer. Please re-install Visual studio

Hi!

I got following exception twice in last 30 days.

“The components required to enumerate web references are not installed on this computer. Please re-install Visual studio

This exception occurs when I change existing web reference Url and point to a new asmx. Why is it asking to re-install visual studio? I would like to avoid re-installing vs 2005 if possible.

Thanks

Prashant

———————————————————————

Hi

did anyone get anywhere with this error ?

All was well with my VS2005 until I published a web site – since then I can’t add or update any web references without seeing this error !

—stop press —

solution in post PostID=107222 worked like a charm !

close VS2005, start | run

devenv /resetskippkgs

No more web refrerence errors after this point.

Thanks,

NM.

January 23, 2009 Posted by dev1 | Visual Studio | | No Comments Yet

Step by step Setting up Gzip on IIS 6 (compressing servers output stream)

1. Allow the compression ISAPI to run IIS 6’s new security system prohibits ISAPI DLLs from running by default, so you need to tell IIS 6 that it’s okay to let the compression ISAPI DLL run.
01. Open the IIS admin tool (inetmgr); drill into your server, and right-click on “Web Service Extensions”.
02. Choose “Add a new web service extension”. For the extension name, use whatever you want to identify it in the list (I used “HTTP Compression Extension”).
03. You need to add a single required file, which is \Windows\System32\inetsrv\gzip.dll, the ISAPI responsible for doing gzip and deflate compression.
04. Check the “Set extension status to allowed”, then click OK.
05. You should have a new web service extension in your list called “HTTP Compression” (or whatever you named it), and it should have a status of “Allowed”.
2. Select compressible content
IIS 6’s compression system only compresses a very limited set of content. You need to enable compression for the appropriate file extensions (specifically, .aspx files for your ASP.NET pages, and perhaps any static content you want compressed as well).

01. You’re going to edit the Metabase. To do this, you first need to shut down IIS.
02. In the IIS admin tool, right click on your server name in the left panel, and choose All Tasks -> Restart IIS.
03. On the restart dialog, choose “Stop internet services” and click OK. When IIS is shut down, you’ll need to edit \Windows\System32\inetsrv\MetaBase.xml (make a backup first!).
04. Search for “IIsCompressionScheme”. There will be two XML elements, one for deflate and one for gzip. Both elements have properties called HcFileExtensions and HcScriptFileExtensions. These contain a space-delimited list of file extension for compressible content.
05. At a bare minimum, you’ll need to add aspx, ascx  to the HcScriptFileExtensions list. Note that if the properties are left blank, then all content, regardless of file extension, will be compressed.

December 30, 2008 Posted by dev1 | .NET, .NET 2.0, ASP.NET, ASP.NET 3.0 | | No Comments Yet

App-Domain could not be created. Error: 0×80131902

Mike Stone tonight came across an interesting issue, not with rainbow, but an issue nonetheless.
When he downloaded and went to run Rainbow 2.0 He came accross the following message

“Failed to execute request because the App-Domain could not be created. Error: 0×80131902″

Basically, this happens on first time 2.0 runs sometimes, not sure why, but the following seems to fix the problem. My suspicions and research lead me to believe it has to do with web servies referenced. To fix it, try the following….

  1. With a command window, get to the latest version of .net under
  2. C:\Windows\Microsoft.Net\Framework\
  3. Now run the following command: “net stop w3svc” to stop web services.
  4. Then use “aspnet_regiis.exe -ua” to uninstall all instances of ASP.NET from IIS.
  5. Follow with “aspnet_regiis.exe -i” to install ASP.NET into IIS.
  6. Now restart web services with “net start w3svc”.

Published venerdì 10 marzo 2006 4.52 by Jonathan

December 23, 2008 Posted by dev1 | ASP.NET 3.0 | | No Comments Yet