2012-08-26 48 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

这是工作...但它不会刷新后编辑.. –

相关问题