2013-01-16 44 views
0

例如:我有10個站點,每個站點有5個列表。從網站1我有一個項目在listX現在id將會像「1」,並在第4個子站點的listB中創建另一個項目,所以現在id將「2」...所以它必須繼續這樣如何實現這一點?是否可以在網站集中爲列表項生成唯一的ID?

我需要更新這與所有列表項添加事件?也如何獲得最新的ID?

回答

0

我曾嘗試與自定義表單驗證碼這是工作的冷靜,但認爲這可能會併發問題

public static void ID() 
    { 
     if ((field.InternalName.Equals("Field1"))) 
           { 
            { 
      string template; 
      using (SPSite site = new SPSite(SPContext.Current.Site.Url)) 
      { 
       using (SPWeb web = site.RootWeb) 
       { 
template = web.Properties["eydtemplate"].ToString(); 
       } 
      } 
      if ("eydadvisory" == template) 
      { 
       SPListItemCollection items = _currentList.Items; 
       if (_currentList.ItemCount == 0) 
       { 
webControl.Field.DefaultValue = (1).ToString(); 
       } 
       else 
       { 
SPQuery query = new SPQuery(); 
query.RowLimit = 1; 
query.Query = " <OrderBy><FieldRef Name='" + field.InternalName + "' Ascending='FALSE' /></OrderBy>"; 
webControl.Field.DefaultValue = (Convert.ToInt64(_currentList.GetItems(query).Cast<SPListItem>().FirstOrDefault()[field.InternalName]) + 1).ToString(); 
       } 
      } 
     }