2012-08-26 44 views
0

我的客戶想要控制網站上的文字內容。他想要一個界面,他可以看到並編輯資源文件文本。如何將資源文件用作可編輯列表視圖的數據源?

成功顯示在列表視圖我的資源文件的內容。 更新是我在哪裏卡住地方。我只是不知道在更新事件中寫什麼。有誰知道一個簡單的方法?

enter image description here

ResourceSet rs = Resources.resfile.ResourceManager. 
        GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true); 

protected void Page_Prerender(object sender, EventArgs e) 
{ 
    ListView1.DataSource = rs; 
    ListView1.DataBind(); 
} 
protected void ListView1_ItemCanceling(object sender, ListViewCancelEventArgs e) 
{ 
    ListView1.EditIndex = -1; 
} 
protected void Updating(Object sender,ListViewUpdateEventArgs e) 
{     
} 

下面的代碼工作,但它的編輯後不刷新,之後我別的東西更新刷新它。

XmlDocument loResource = new XmlDocument(); 
loResource.Load(Server.MapPath("/App_GlobalResources/resfile.resx")); 

XmlNode loRoot = loResource.SelectSingleNode(
          string.Format("root/data[@name='{0}']/value",e.Keys[0].ToString())); 

if (loRoot != null) 
{ 
    loRoot.InnerText = e.NewValues[1].ToString(); 
    loResource.Save(Server.MapPath("/App_GlobalResources/resfile.resx")); 
}  
ListView1.EditIndex = -1; 

回答

1

我只是做了你的問題,的演示注意到了同樣的問題。圍繞谷歌搜索和閱讀,我偶然發現accros這個blog裏克施特拉爾一些論壇條目後指出:

清爽資源

你所做的資源的變化之後,您可能真的喜歡到 看到新的資源顯示在實時用戶界面中。 [...] ASP.NET的資源提供程序加載資源資源 永遠被緩存,直到應用程序關閉據我 知道有釋放資源沒有內置的方式,但這裏的數據 提供商包括用於跟蹤每個提供一些邏輯[...]

正如我不想實現一個數據庫來存儲可以更新的資​​源我試過這個非常骯髒的小東西!只是所謂的Response.Redirect和強迫一個完整的新Page.Request從瀏覽器。所以服務器獲得新的響應並重新緩存資源!

我知道,這是沒有很好的解決方案,但它爲我工作。我嘗試重新綁定資源,卸載appDomain等 - 沒有工作!我希望這個答案能幫助你!

protected void ListView1_ItemUpdating(Object sender, ListViewUpdateEventArgs e) 
{ 
    string key = e.Keys[0].ToString(); 
    string value = e.NewValues[0].ToString(); 

    XmlDocument loResource = new XmlDocument(); 
    loResource.Load(Server.MapPath("App_GlobalResources/resFile.resx")); 

    XmlNode loRoot = loResource.SelectSingleNode(
           string.Format("root/data[@name='{0}']/value", key)); 

    if (loRoot != null) 
    { 
     loRoot.InnerText = value; 
     loResource.Save(Server.MapPath("App_GlobalResources/resfile.resx")); 
    } 

    ListView1.EditIndex = -1; 
    Response.Redirect("demo.aspx"); // that's all!!! 
} 
+0

在SO上找到這個主題http://stackoverflow.com/questions/6480963/sliding-expiration-of-localized- asp-net-resources –

+1

天才!它完美運作 –

0

這裏的代碼項目,它說明了如何更新列表視圖: http://www.codeproject.com/Articles/24570/Complete-ListView-in-ASP-NET-3-5

+0

笑。 我是SQL數據源,很容易。我想編輯ResourceSet。 –

+0

XmlDocument loResource = new XmlDocument(); loResource.Load(使用Server.Mappath(「/ App_GlobalResources文件/ resfile。();); XmlNode loRoot = loResource.SelectSingleNode(string.Format(「root/data [@name ='{0}']/value」,e.Keys [0] .ToString())); 如果(loRoot!= NULL){ loRoot.InnerText = e.NewValues [1]的ToString(); loResource.Save(使用Server.Mappath( 「/ App_GlobalResources文件/ resfile.resx」));} ListView1.EditIndex = -1; –

+0

這是工作...但它不會刷新後編輯.. –

相關問題