2013-07-18 87 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文件夾內。