Delicious Facebook RSS Feed

String Format for Double [C#]

Chữ số sau dấu thập phân
Ví dụ chuyển định dạng Double thành chuỗi với số cố định của dấu thập phân. Với mẫu định dạng "0.00" nếu  số lượng số sau dấu chấm: nếu ít hơn 2 các chữ số còn lại ở bên phải sẽ là zero. Nếu nó có nhiều nơi hơn 2, số lượng sẽ được thêm số zero để đủ thành 2 số sau dấu chấm

String.Format("{0:0.00}", 123.4567);      // "123.46"
String.Format("{0:0.00}", 123.4);         // "123.40"
String.Format("{0:0.00}", 123.0);         // "123.00"
Khác với mẫu "0.00", mẫu "0.##" là có bao nhiêu hiện bấy nhiêu nhưng nhỏ hơn hoặc bằng số lượng quy định mà không tự thêm zero vào
String.Format("{0:0.##}", 123.4567);      // "123.46"
String.Format("{0:0.##}", 123.4);         // "123.4"
String.Format("{0:0.##}", 123.0);         // "123"
Ví dụ bên dưới sẽ giúp hiểu rõ 2 kí hiệu "0" và "#"
String.Format("{0:0.0}", 0.0);            // "0.0"
String.Format("{0:0.#}", 0.0);            // "0"
String.Format("{0:#.0}", 0.0);            // ".0"
String.Format("{0:#.#}", 0.0);            // "

Digits before decimal point

String.Format("{0:0.0}", 0.0);                            // "0.0"
String.Format("{0:0.#}", 0.0);                            // "0"
String.Format("{0:#.0}", 0.0);                            // ".0"
String.Format("{0:#.#}", 0.0);                            // ""

 

 

OnClick và Href

Ví dụ 1: Rê chuột vào link sẽ chỉ là liên kết hiện tại trang đang đứng nhưng khi click vào link thì sẽ thực hiện js bất kì trong trừơng hợp này là alert().
Nhược điểm: không click chuột phải New tab hay new window dc, đường link khi rê chuột vào không thể hiện chính xác url ở thanh status nếu như sự kiện oclick là openwindow tới 1 trang khác
<a href="#" onclick="alert('ne')" >Link</a>
Kết quả:
Link

Ví dụ 2: Ở thanh trạng thái status chỉ xuất hiện dòng "javascript:alert('nè')" trong thẻ href.
Nhược điểm: không click chuột phải New tab hay new window dc.
<a href="javascript:alert('ne')"  >Link</a>
Kết quả:
Link

Ví dụ 3: Khắc phục 2 cách trên, thanh status thể hiện chính xác url khi click vào link nên click chuột phải new tab cũng dc. thêm sự kiện js xử lí khi click. event.ctrlKey là bool trả về khi nhấn phím Ctrl và window.opera trả về bool khi trình duyệt là opera.
Giải thích onclick: nếu ko nhấn phím Ctrl và trình duyệt ko phải là opera thì alert lên và vô hiệu hóa thuộc tính href bởi lệnh return false, nghĩa là click vào link xuất hiện alert nhưng ko nhảy tới trang web dc ghi trong thẻ href. Ngược lại các trường hợp khac thì nhảy tới url mô tả trong href.

<a href="http://www.blogger.com" onclick="if(!event.ctrlKey&&!window.opera){ alert("nè") ;return false;}else{return true;}" target="_blank" >Link</a>
Kết quả:
Link

CSS: hiểu về Position

 Positon co 4 thuộc tính:
  • static
  • absolute
  • relative
  • fixed
Static là thuộc tính mặc định
Static is the default position for any element on a Web page. If you don't define the position, it will be static and will display on the screen based on where it is in the HTML document and how it would display inside the normal flow of the document.
If you apply positioning rules like top or left to an element that has a static position, those rules will be ignored.
 Absolute:
This tells the browser that whatever is going to be positioned should be removed from the normal flow of the document and will be placed in an exact location on the page. It is also taken out of the normal flow of the document - it won't affect how the elements before it or after it in the HTML are positioned on the Web page. 
The four positioning properties are:
To use them, you need to think of them as offset properties. In other words, an element positioned right 2em is not moved right 2em. It's right side is offset from the right side of the window 2em. The same is true for the other three.
 Nếu dùng right với thuộc tính absolute 2em có nghĩa là khoảng cách chính xác tính từ cạnh bên phải của cửa sổ window tới bên phải của đối tượng chứ ko phải là dịch sang phải 2em
offset có thể dịch là sự dịch chuyển hoặc bù đắp, khỏang chừa trống


Relative:
Relative positioning uses the same four positioning properties as absolute positioning. But instead of basing the position of the element upon the browser view port, it starts from where the element would be if it were still in the normal flow.
 Giá trị relative dựa trên hướng đi bình thường dựa trên các thuộc tính cha nếu thuoc tính cha cũng theo hướng bình thường
Với right, left,top, bottom:

Từ  hình trên ta có thể thấy right khỏang cách bao nhiêu phụ thuộc vào vị trí ban đầu trước khi có giá trị right, khác với absolute

Absolute và Relative


Fixed:

Fixed positioning is a lot like absolute positioning. The position of the element is calculated in the same way as the absolute model - from the sides of the view port. But fixed elements are then fixed in that location, like a watermark. Everything else on the page will then scroll past that element.
Cũng giống như absolute nhưng fixed thì sẽ luôn cố định xuất hiện trên window nếu bạn scroll

Sự khác nhau absolute và relative
Vấn đề Position luôn làm đau đầu với người mới tìm hiểu về position là absolute và relative:
- Đầu tiên ta coi ví dụ sau về absolute http://www.yourhtmlsource.com/examples/positioning1.html
Source:
<html>
<body id="htmlsource">
<img src="../updates/progress/media/feature.gif" width="100" height="100" alt="Absolutely positioned image." border="1" style="position: absolute; top: 56px; right: 80px">

<img src="../updates/progress/media/feature.gif" width="100" height="100" alt="This image was placed here using css2 absolute positioning" border="1" style="position: absolute; top: 100px; left: 360px; ">

<p>See? That image to the right is <em>exactly</em> where I told it to be, in relation to this page. Oh, and I put in the border so you can see where the image edges go.</p>

<br><br><br><br><br><br>
<p>I can even obscure this text by placing an image on top of it like this. Hello? Hello?? Oh, good, I'm back. Do you see?</p>

<p>It's just a matter of trying out different values and getting the element exactly where you wanted it.</p>

</body>
</html>
Kết hợp với plugin firebug của FF để view source rõ thêm
- Giờ ta phân tích sự khác nhau cơ bản của 2 thuộc tính absolute và relative: đó là thẻ <HTML> và thẻ <BODY>
Ta sửa style hình 1 và 2 thành :
hình 1: position: relative; left: 0pt; top: 0pt;
hình 2: position: absolute; left: 0pt; top: 0pt;
Ta dc kết quả: hình 1 dc kẻ khung đỏ

Phân tích thẻ <body>:
Đưa chuột vào thẻ body dc tô nền màu xanh, còn màu vàng là margin của thẻ body (coi thuộc tính thẻ body).
ta thấy hình 1 với thuộc tính relative nằm bên trong thẻ body, trong khi hình 2 thuộc tính absolute thì dc nằm trong thẻ <html>
Với hình 2 trong thẻ html:

Kết luận:
- Thuộc tính absolute chịu ảnh hưởng đầu tiên từ thẻ html và thuộc tính relative chịu ảnh hưởng đầu tiên từ thẻ body
- Đối với thuộc tính relative: sẽ chịu ảnh hưởng trực tiếp thẻ cha của nó mà ko từ thẻ <body> nữa nếu thẻ cha của nó dc khai báo thuộc tính relative

Link đọc thêm và có ví dụ: http://www.barelyfitz.com/screencast/html-training/css/positioning/

Window size and scrolling

Chiều nay làm window scroll thì gặp vấn đề giữa IE và W3C, ta biết chuẩn IE khác biệt so với W3C, vậy nếu với dòng code sau:
document.body.scrollLeft
Sẽ chạy bình thường trong IE, nhưng vào trong html của mình có khai báo:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
Thì giá trị luôn trả về là 0. giải thích vì từ đây html của mình sẽ tuân thủ chuẩn W3C và
document.body.scrollLeft không có hỗ trợ trong W3C. 
Giải quyết với chuẩn W3C ta phải dùng :
document.documentElement.scrollLeft
Giải quyết cross browsers: nhận diện browser cụ thể để dùng hàm tương ứng
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
} 

Đọc thêm về size: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

Chèn Syntax Highlighter vào Blogger


 Hôm nay lang thang đưa bài về jquery plugin thấy editor của blogger thiếu thiếu gì đó, chèn code nó ko dc đẹp, đi tìm cái layout cho nó đẹp 1 tí, kết quả là Syntax Highlighter, cái thường thấy trên web mà ko biết là cái gì, giới thiệu mọi ng, 2 link dưới làm theo 1 trong 2 là có thể chèn code vào với layout đẹp liền à.
Syntax Highlighter phiên bản cũ : http://heisencoder.net/2009/01/adding-syntax-highlighting-to-blogger.html
Phiên bản mới: http://www.bloggermint.com/2010/02/how-to-add-syntax-highlighter-for-bloggerblogspot/

2 trang html Escape:
http://www.accessify.com/tools-and-wizards/developer-tools/quick-escape/default.php
http://www.elliotswan.com/postable/

cập nhật 22/10/2010:
kiếm thêm dc vài bài viết hay trên mạng:
http://hontap.blogspot.com/2010/04/lam-ep-code-trong-blog-voi.html
Làm theme mới  Highlighter
 http://davidchambersdesign.com/coda-theme-for-syntaxhighlighter/

Tạo Plugin cho jQuery



Chain Pattern:

Chain Pattern: http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern. Đây là một pattern trong thiết kế phần mềm. Yêu cầu đặt ra là các hàm xử lý sau khi tính toán xong thì kết quả return về chính các tham số được nhận vào. Làm điều này tốt thì chúng ta có thể sử dụng và gọi các hàm xử lý liên tiếp nhau và mã nguồn sẽ dễ đọc hiểu hơn.

Giới thiệu cách hoạt động của jQuery plugin

jQuery là một bộ thư viện Javascript sử dụng rất tốt Chain Pattern. Ví dụ là để gọi 2 hàm show() và hide() thay vì cách dùng truyền thống là:
$(document).show();
$(document).hide();
thì với jQuery chúng ta có thêm cách sử dụng như sau:
$(document).show().hide();
Đây chính là cách sử dụng dựa vào Chain Pattern, và đây cũng là nguyên tắc cơ bản khi viết một plugin cho jQuery. Phải đảm bảo plugin của chúng ta thỏa mãn yêu cầu này để những người sử dụng plugin của chúng ta có thể linh hoạt trong việc sử dụng.

Cách hoạt động của jQuery plugin

jQuery lưu các hàm có thể gọi trực tiếp từ selector trong jQuery.fn. Như ví dụ trên thì showhide là 2 hàm nằm trong jQuery.fn. Khi viết plugin chúng ta cũng tạo các hàm xử lý của chúng ta và gắn vào cho jQuery.fn - Nhớ là phải đảm bảo yêu cầu ở trên (Chain Pattern).

Mã nguồn mẫu:

Để thỏa mãn 2 yêu cầu ở trên ta sẽ có cách viết plugin như sau (Đây chỉ là một trong nhiều cách viết - và đa số các plugin hiện tại đều viết theo cách này):
(function ($) {
  $.extend($.fn, {
    myPlugin: function () {
      return this.each(function () {
        // Ma nguon cua chung ta tai day
      })
    }
  })
})(jQuery);

myPlugin là tên mà chúng ta người sử dụng sẽ gọi khi muốn xài plugin của chúng ta. Sau đó plugin của chúng ta sẽ được chạy khi được gọi bằng $(selector).myPlugin();
Giải thích:
  • Đầu tiên là chúng ta bỏ toàn bộ mã nguồn của plugin vào trong một Anonymous function:

    (function ($) {
    })(jQuery);
    Điều này bảo đảm cho việc những ai sử dụng plugin của chúng ta hoàn toàn có thể tạo ra các hàm khác trùng tên mà không bị xung đột với các hàm đã có của chúng ta. Và giá trị của các biến, hàm... của chúng ta tạo ra chỉ tồn tại trong phạm vi của hàm này. Ở đây chúng ta cũng làm luôn một việc là đặt shorthand cho tên jQuery thành $. Nghĩa là thay vì sử dụng jQuery.fn chúng ta có thể sử dụng $.fn mà không sợ bị xung đột với các biến $ ở ngoài hàm này. (tham khảo thêm phần jQuery.noConflict)
  • Tiếp theo chúng ta sử dụng hàm $.extend để thêm hàm của chúng ta vào cho đối tượng $.fn như đã nói ở trên (Lưu giữ các plugin)

    $.extend($.fn, {
    });
    Như vậy là chúng ta sẽ thêm vào cho $.fn những plugin do chúng ta tạo ra.
  • Và đây là mã nguồn chính của plugin:

       myPlugin: function () {
        }
    Có nghĩa là chúng ta đặt tên plugin của chúng ta là myPlugin, người sử dụng muốn xài plugin của chúng ta thì phải dùng hàm myPlugin(). Nội dung của hàm này là:

    return this.each(function () {
      // Ma nguon cua chung ta tai day
    })
    Đầu tiên chúng ta trả về kết quả là các tham số được nhận. Sử dụng this.each để bảo đảm không bỏ xót các tham số (jQuery có thể tương tác với nhiều đối tượng cùng lúc). Sau đó là các xử lý logic của plugin.

Ví dụ minh họa:

  • Ta có mã HTML:

    <span id="example1">Ví dụ 1</span>
    <div id="example2">Ví dụ 2</div>
  • Yêu cầu: Viết một plugin thực hiện nhiệm vụ là đổi màu nền của element thành đỏ và khi được click chuột thì alert nội dung của element đó.
  • Thực hiện: Dựa vào mã nguồn mẫu trên ta sẽ có kết quả như sau:

Ví dụ 1
Ví dụ 2


Nguồn: http://www.sanglt.com/Xay-dung-plugin-cho-jQuery 

Plugin có tham số

abc
abc
Source nguồn:
(function($){
  $.fn.extend({ 
   
   fnexample: function(options) {
   var defaults = {
    paddingLeft: 20,
    mouseOverColor : '#000000',
    mouseOutColor : '#ffffff'
   }

   var options =  $.extend(defaults, options);

      return this.each(function() {
          var opts = options;   
          $(this).click(function () {
            alert(opts.paddingLeft);
            }).css('padding-left',opts.paddingLeft);
      });
     }
 });
 
})(jQuery);
Cách sử dụng:
$(document).ready(function () {
  $('#example3').fnexample();
  $('#example4').fnexample({paddingLeft:40});
});
Dòng 2 sử dụng tham số mặc định của hàm .fnexample đã được định nghĩa chính bên trong nó. Dòng 3 truyền tham số bên ngòai vào
Đọc thêm: các ví dụ này rất hay http://www.queness.com/post/112/a-really-simple-jquery-plugin-tutorial http://www.bennadel.com/blog/800-My-First-jQuery-Plugin.htm
Video hướng dẫn làm plugin trong 5 phút:

SharePoint WebPart Property Attributes

WebBrowsable [WebBrowsable(True)]"Indicates whether the designated property of a Web Parts control is displayed in a PropertyGridEditorPart object." (MSDN)
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webbrowsableattribute.aspx
WebPartStorage [WebPartStorage(Storage.Personal)]This attribute specifies what type of storage options the WebPart will make use of. The most common is Storage.Personal. "This property can be personalized by individual users. Its WebPartStorageAttribute value is Storage.Personal, which specifies that the property can be stored on a per-user basis. Only users with the Personalize Web Part pages right can set this property." (MSDN)
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpartstorageattribute.aspx
Personalizable [Personalizable(true)]Allows users the ability to personalize settings for the WebPart.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.personalizableattribute.aspx
WebDispayName [WebDisplayName(string)]Defines the Friendly Name for a property of a WebPart control. This is the name that will show up in the editor screen.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webdisplaynameattribute.aspx
WebDescription [WebDescription(string)]Defines the string value to use as a ToolTip for a property of a Web Parts control. (MSDN)
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webdescriptionattribute.aspx
SPWebCategoryName [SPWebCategoryName(string)]Defines the friendly or localized name of the category of a property in the CustomPropertyToolPartcontrol inside the ToolPane.
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.spwebcategorynameattribute.aspx
ConnectionProvider [ConnectionProvider(string)] Identifies the callback method in a server control acting as the provider in a Web Parts connection, and enables developers to specify details about the provider's connection point. (MSDN) This is used to create connectable WebParts.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.connectionproviderattribute.aspx
ConnectionConsumer [ConnectionConsumer(string)]Identifies the callback method in a server control acting as the consumer in a Web Parts connection, and enables developers to specify details about the consumer's connection point. (MSDN) This is used to create connectable WebParts.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.connectionconsumerattribute.aspx
Below is an example of how to use these attributes in your WebPart code.
[WebBrowsable(true),
Personalizable(false),
WebPartStorage(Storage.Personal),
WebDisplayName("User Name(Domain\\username)"),
WebDescription("User to display in the WebPart."),
SPWebCategoryName("Options")]
public string UserLoginName
{
    get { return _loginName; }
    set { _loginName = value; }
}

Custom context menu trong SharePoint



Căn Bản
Đầu tiên là tạo một custom context đã, nó là gì bạn có thể xem hình bên dứơi:


  Nếu muốn thêm thuộc tính trong Context menu thì làm sao ?

1. Add thêm webpart

2. Chọn Content Editor, lưu ý web part Content Editor phải nằm trước web part List, để chắc rằng script dc thực thi trước. xem thêm nguồn tham khảo bên dứơi:


3. View Source, copy đọan bên dưới:

function Custom_AddDocLibMenuItems(m, ctx)
{
var strDisplayText = “Navigate to Google”;
var strAction = “STSNavigate(‘http://www.google.com’)”;
var strImagePath = “”;
CAMOpt(m, strDisplayText, strAction, strImagePath);
CAMSep(m);
return false;
}


5. Kết quả


Chú ý:
1. “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\" Hàm js sử dụng trong ví dụ trên nằm trong OWS.JS
2. Nếu là Document Library thì dùng hàm
Custom_AddDocLibMenuItems, nếu là List thì dùng Custom_AddListMenuItems

Nguồn tham khảo: http://www.mstechblogs.com/shailaja/create-a-custom-context-menu-in-sharepoint-list-or-document-library/



Nâng cao
Nguồn đọc thêm: http://blogs.msdn.com/b/bowerm/archive/2004/07/07/175691.aspx
http://sharepointstudio.markstokes.com/2005/11/add-context-menu-send-document-link-by.html
http://stackoverflow.com/questions/745499/sharepoint-custom-context-menu-in-custom-list-appears-on-folders-and-not-just-fil 

Nên đọc thêm 3 link trên. coi thêm các file js của sharepoint OWS.JS, CORE.JS, IMGLIB.JS ở thư mục C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033.

Bây giờ ta giải thix 1 chút về các hàm đã sử dụng là Custom_AddDocLibMenuItems hay Custom_AddDocLibMenuItems.
function Custom_AddDocLibMenuItems(m, ctx)
tham số m chưa có giá trị ban đầu, nó chỉ có sau khi chạy hàm này
CAMOpt(m, strDisplayText, strAction, strImagePath);
giá trị trả về là chính nội dung strDisplayText trong thẻ span. muốn biết thì alert(m.innerHTML)

Coi thông tin biến ctx, từ view source ta thấy:

ctx = new ContextInfo();
ctx.listBaseType = 1;
ctx.listTemplate = 109;
ctx.listName = "{9370E172-8760-4303-AE31-E9426126B6ED}";
ctx.view = "{FE7A0018-7358-4B70-972D-5799B43F095C}";
ctx.listUrlDir = "\u002fnews\u002fLists\u002fPhotos";
ctx.HttpPath = "\u002fnews\u002f_vti_bin\u002fowssvr.dll?CS=65001";
ctx.HttpRoot = "http:\u002f\u002fnqnguyen\u002fnews";
ctx.imagesPath = "\u002f_layouts\u002fimages\u002f";
ctx.PortalUrl = "";
ctx.SendToLocationName = "";
ctx.SendToLocationUrl = "";
ctx.RecycleBinEnabled = -1;
ctx.OfficialFileName = "";
ctx.WriteSecurity = "1";
ctx.SiteTitle = "Tin T\u1ee9c";
ctx.ListTitle = "Photos";
if (ctx.PortalUrl == "") ctx.PortalUrl = null;
ctx.displayFormUrl = "\u002fnews\u002fLists\u002fPhotos\u002fForms\u002fDispForm.aspx";
ctx.editFormUrl = "\u002fnews\u002fLists\u002fPhotos\u002fForms\u002fEditForm.aspx";
ctx.isWebEditorPreview = 0;
ctx.ctxId = 1;
g_ViewIdToViewCounterMap[ "{FE7A0018-7358-4B70-972D-5799B43F095C}" ]= 1;
ctx.CurrentUserId = -1;


ví dụ site của tôi trong trường hợp trên. có lúc bạn sẽ cần chúng.

Ngòai ra trong source ta sẽ thấy đọan script sau:

Đọan script này dc lặp lại tương ứng với số lượng row trong list.
Để ý hàm InsertItem nó dc định nghĩa trong IMGLIB.JS:
function InsertItem(originalImageUrl, id, baseName, extension, imgWidthStr, imgHeightStr, titleStr, descriptionStr, objectType, iconUrl, fNewItem)
{
 if (originalImageUrl=="")
  return;
 items[id]=new CItem(originalImageUrl, id, baseName, extension, imgWidthStr, imgHeightStr, titleStr, descriptionStr, objectType, iconUrl, fNewItem);
 if (firstId==-1)  firstId=id;
 ids[ids.length]=id;
} 
Ở đây có hàm CItem sẽ add các thông số vào mảng items <- mọi thông tin của từng row trong list sẽ nằm trong mảng này --> ta đã có mọi thứ.
Vấn đề giờ sao lấy dc id ?
Quay lại giao diện, ta để ý mỗi nút nhấn sổ xuống context menu đều có hàm ClickRow kèm với tham số ID tương ứng với dòng dc click, hàm này cũng ở trong IMGLIB.JS
function ClickRow(id)
{
 if (!fImglibDefautlView) return;
 if (tbPreview==null)
  return;
 if (id < 0 || items[id]==null)
  return;
 if (browseris.ie)
  event.cancelBubble=true;
 HiLiteRow(id);
 ILShowMenu(id);
}
Coi hàm ILShowMenu , trong hàm này có dòng itemTable=menuTR.parentNode.parentNode;
trả về tòan bộ html tương ứng của cột có context menu của từng dòng dc click.
Trong đọan html này có thuộc tính id, ta chỉ cần get attribute về và cắt lấy chuỗi id vì nó dc ghép với "title"+id.

var txtID=itemTable.childNodes[0].childNodes[0].getAttribute("id");
var id=txtID.substr(5); 

Update 10/9/2010

Sau time tiếp tục nghiên cứu thấy: đọan script InsertItem chỉ có ở view có style là Picture Library Details , còn chỉnh sang
view có style khác như Basic Table thì sẽ ko lấy dc biến Items...-->đau đầu.
Khắc phục tạm thời: dùng js hoặc jquery để select trong source tìm giá trị phù hợp