2011-12-15 14 views
1

Visual Studioを使用してWebパーツを作成し、リストの選択した列をgridviewに表示しました。しかし、問題は、ロケールを英語 - 英国(デフォルトでは英語 - 米国)に変更するときはいつでも、日付フォーマットは変更されるはずですが、残念ながらサイトだけでなく影響はありません。Sharepointの地域設定

私はロケールと日付形式を変更するには、次のコードを試してみました:

protected void btnClick_Event(object sender, EventArgs e) 
    { 
     using (SPSite osite = new SPSite(SPContext.Current.Web.Url)) 
     { 
      using (SPWeb oweb = osite.OpenWeb()) 
      { 
       if (DropDownList1.SelectedValue == "English-UK") 
       { 
        oweb.AllowUnsafeUpdates = true; 
        oweb.Locale = new System.Globalization.CultureInfo("en-GB"); 
        oweb.Update(); 
       } 
       else if(DropDownList1.SelectedValue == "English-US") 
       { 
        oweb.Locale = new System.Globalization.CultureInfo("en-US"); 
        oweb.Update(); 
       } 

       lblmsg.Text = "Region changed successfully";   
      } 
     } 
    } 

Webパーツのコードを次のとおりです。

ウェブのRegionalSettingsでのLocaleIDをされた設定
using System; 
using System.ComponentModel; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using Microsoft.SharePoint; 
using Microsoft.SharePoint.WebControls; 
using System.Data; 

namespace SharePointProject100.CustomGridWebpart 
{ 
    [ToolboxItemAttribute(false)] 
    public class CustomGridWebpart : WebPart 
    { 

    SPGridView grdview = new SPGridView(); 
    protected override void CreateChildControls() 
    { 
     grdview.ID = "grdview"; 
     grdview.AutoGenerateColumns = false; 

     this.Controls.Add(grdview); 
     using (SPSite osite = new SPSite(SPContext.Current.Web.Url)) 
     { 
      using (SPWeb web = osite.OpenWeb()) 
      { 
       SPList mylist = web.Lists["EmployeeDetails"]; 
       BindToGrid(mylist, grdview); 
      } 
     } 
    } 

    private void BindToGrid(SPList myList, SPGridView gridView) 
    { 
     // get all the listitem 
     SPListItemCollection results = myList.Items; 

     // create the datatable object 
     DataTable table = new DataTable(); 
     table.Columns.Add("Employee Name", typeof(string)); 
     table.Columns.Add("DOB", typeof(string)); 
     table.Columns.Add("JoiningDate", typeof(string)); 
     table.Columns.Add("MembershipExpiryDate", typeof(string)); 

     // Create rows for each splistitem 
     DataRow row; 
     foreach (SPListItem result in results) 
     { 
      row = table.Rows.Add(); 
      row["Employee Name"] = Convert.ToString(result["Employee Name"]); 
      row["DOB"] = Convert.ToString(result["DOB"]); 
      row["JoiningDate"] = Convert.ToString(result["JoiningDate"]); 
      row["MembershipExpiryDate"] = Convert.ToString(result["MembershipExpiryDate"]); 
     } 

     // create the bound fields 
     SPBoundField boundField; 
     boundField = new SPBoundField(); 
     boundField.HeaderText = "Employee Name"; 
     boundField.DataField = "Employee Name"; 
     boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
     boundField.ItemStyle.Wrap = false; 
     gridView.Columns.Add(boundField); 

     boundField = new SPBoundField(); 
     boundField.HeaderText = "DOB"; 
     boundField.DataField = "DOB"; 
     boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
     boundField.ItemStyle.Wrap = false; 
     gridView.Columns.Add(boundField); 

     boundField = new SPBoundField(); 
     boundField.HeaderText = "JoiningDate"; 
     boundField.DataField = "JoiningDate"; 
     boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
     boundField.ItemStyle.Wrap = false; 
     gridView.Columns.Add(boundField); 

     boundField = new SPBoundField(); 
     boundField.HeaderText = "MembershipExpiryDate"; 
     boundField.DataField = "MembershipExpiryDate"; 
     boundField.ItemStyle.HorizontalAlign = HorizontalAlign.Center; 
     boundField.ItemStyle.Wrap = false; 
     gridView.Columns.Add(boundField); 

     gridView.AutoGenerateColumns = false; 
     gridView.DataSource = table.DefaultView; 
     gridView.DataBind(); 
    } 
} 

}

+0

サイトアクション - >サイト設定 - >サイト管理 - >地域設定 –

+0

いいえ、特定のサイト内ではまったく動作しません。 –

+0

実際には、このプログラムをコーディングで解決する必要があります。私はそうしようとしましたが、動作しませんでした。プログラム形式でロケールを変更できますが、日付形式は変更できません。 –

答えて

1

それを "汚い"(ILSpyの逆アセンブルされたコードを見て)印を付けることになっていましたが、私はその変更に基づいて他の祖先を "更新"することができませんでした。

関連する問題