使用资源键在绑定字段中的标题文本

时间:2013-07-18 06:48:57

标签: c# asp.net .net

我正在尝试将Resource键添加到网格视图的标题文本中,但经过很长时间,我无法管理此问题。

我尝试过编码:

<asp:BoundField DataField="CategoryName"  HeaderText="<%$ Resources:ViewTC_CourseCategory,HeaderCategoryName %>"
                 ItemStyle-Width="12">
    <ItemStyle HorizontalAlign="Center" />
</asp:BoundField>

我的资源文件包含如下值:

HeaderCategoryName.Text           Category Name

它显示以下错误:The resource object with key 'HeaderCategoryName' was not found

实施此要求的正确方法是什么。请提供帮助。

2 个答案:

答案 0 :(得分:3)

试试这个

  void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {

    if(e.Row.RowType == DataControlRowType.HeaderRow)
    {
      // use the index of your cell
      e.Row.Cells[0].Text = "Your Resource file string";
    }

  }

答案 1 :(得分:2)

请确保资源文件名称和页面名称符合ASP.NET用于搜索本地资源文件的约定:

1。)如果页面名称为:Sample.ascx,则资源文件名必须为:sample.ascx.resx。

2.。)还要确保App_LocalResource文件夹(包含sample.ascx.resx)位于UserControls文件夹中。