2013-07-18 34 views
3

我试图将资源键添加到网格视图的标题文本,但经过很长时间后,我无法管理此问题。使用资源键的绑定字段中的标题文本

我已经试过编码,如:

<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

什么是实现这个正确的方法需求。一定帮助。

+0

你能告诉你的资源文件和GridView所在页面的名称是什么? –

+0

资源文件名称:ViewTC_CourseCategory.ascx.resx页面名称:ViewTC_CourseCategory.aspx – Abhishek

+0

我试着实现这个:” ItemStyle-Width =“12”> Abhishek

回答

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

    } 
+0

我试图实现这一点,但它没有帮助。我已更新上面的错误.. – Abhishek

2

请确保资源文件名称和页面名称是按照使用ASP.NET来搜索本地资源文件公约:

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

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