ASP.NET、GridView、BoundField、HeaderText 翻译
当我定义了一个新的资源文件时,我遇到了 HeaderText 没有被翻译的问题。所有其他文本都会翻译,但 HeaderText 不会,甚至 TemplateField.HeaderText 也会被翻译。
<asp:GridView ID="GridView1" runat="server"
PageSize="25" GridLines="None"
AutoGenerateColumns="False" Width="100%"
meta:resourcekey="GridView1Resource1">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title"
meta:resourcekey="BoundFieldResource1" />
<asp:BoundField DataField="Created" HeaderText="Skapad"
meta:resourcekey="BoundFieldResource2" />
<asp:BoundField DataField="CreatedBy" HeaderText="Skapad av"
meta:resourcekey="BoundFieldResource3" />
<asp:TemplateField HeaderText="Till" meta:resourcekey="TemplateFieldResource1">
<ItemTemplate>
<asp:Label ID="lblTo" runat="server" Text="Till"
meta:resourcekey="lblToResource1" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField meta:resourcekey="TemplateFieldResource2">
<ItemTemplate>
<asp:HyperLink ID="hplPopup" runat="server" Text="Öppna"
meta:resourcekey="hplPopupResource1"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="foot" />
<PagerStyle CssClass="pager" />
<SelectedRowStyle CssClass="selected" />
</asp:GridView>
Im having a problem with the HeaderText not being translated when i have definied a new resource file.. all other text do translate but not the HeaderText, even the TemplateField.HeaderText gets translated.
<asp:GridView ID="GridView1" runat="server"
PageSize="25" GridLines="None"
AutoGenerateColumns="False" Width="100%"
meta:resourcekey="GridView1Resource1">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title"
meta:resourcekey="BoundFieldResource1" />
<asp:BoundField DataField="Created" HeaderText="Skapad"
meta:resourcekey="BoundFieldResource2" />
<asp:BoundField DataField="CreatedBy" HeaderText="Skapad av"
meta:resourcekey="BoundFieldResource3" />
<asp:TemplateField HeaderText="Till" meta:resourcekey="TemplateFieldResource1">
<ItemTemplate>
<asp:Label ID="lblTo" runat="server" Text="Till"
meta:resourcekey="lblToResource1" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField meta:resourcekey="TemplateFieldResource2">
<ItemTemplate>
<asp:HyperLink ID="hplPopup" runat="server" Text="Öppna"
meta:resourcekey="hplPopupResource1"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="foot" />
<PagerStyle CssClass="pager" />
<SelectedRowStyle CssClass="selected" />
</asp:GridView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行类似的操作,其中 TitleHeaderText 是资源的名称(示例代码,未经测试):
这里解释如何访问网页资源。
You could do something like this, where TitleHeaderText would be the name of the resource (example code, untested):
Here's an explaination of how to access web page resources.
问题可能不在您的代码中,而是在您的“.resx”文件中。
“TemplateField”不包含属性“.Text”,它包含“.HeaderText”属性,这与最常见的“.resx”引用相反,该引用仅引用包含 Text="MyText" 属性的标签和其他元素
例如!
yourResxReference.Text
<-- 必须是-->yourResxReference.HeaderText
这是实际代码的示例
应该是
The problem may not in your code, Is in your ".resx" file.
A "TemplateField" does not contain an attribute ".Text" it contains a ".HeaderText" attribute, as oppose to the most common ".resx" reference that only reference labels and other elements that contain Text="MyText" attributes
For example!
yourResxReference.Text
<-- Must Be -->yourResxReference.HeaderText
Here is an example from actual code
Should be