Sharepoint区域设置

时间:2011-12-15 09:56:32

标签: sharepoint-2010

我使用Visual Studio创建了一个Web部件,以在gridview中显示列表的选定列。但问题是,每当我将语言环境改为英语 - 英语(默认情况下是英语 - 美国)时,不幸的是它和网站对它没有影响,尽管日期格式应该被更改。

我尝试使用以下代码来更改区域设置和日期格式:

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";           
            }
        }
    }

Webpart代码如下:

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();
    }
}

}

1 个答案:

答案 0 :(得分:1)

在Web的RegionalSettings中设置LocaleID应该将其标记为“脏”(查看ILSpy中的反汇编代码),但我没有任何运气,然后让它根据该更改“更新”其他属性