Setting the localisation value of the header text of a datagrid Consider the following single column datagrid.
<asp:datagrid id="grdListItem" Visible="False" OnPageIndexChanged="grdListItemPage" AllowPaging="True" bordercolor="transparent" Borderwidth="0" CellPadding="4" <AutoGenerateColumns="False" runat="server" GridLines="None" width="400px">
<ALTERNATINGITEMSTYLEBackColor="Gainsboro"></ALTERNATINGITEMSTYLE>
<ITEMSTYLE BackColor="WhiteSmoke" Font-Size="10px" Font-Names= "Verdana"HorizontalAlign="Right"></ITEMSTYLE>
<HEADERSTYLECssClass="janetarticles_datagridheader"></HEADERSTYLE>
<PAGERSTYLE CssClass= "janetarticles_datagridPage"Mode="NumericPages"></PAGERSTYLE>
<COLUMNS>
<asp:TemplateColumn HeaderText="Name">ITEMSTYLE HorizontalAlign="Left">
<ITEMTEMPLATE>
<asp:Label id="id" Visible="False" runat="server" Text='
' NAME="id">
<asp:Label id="name" runat="server" Text='
'NAME="name"></asp:Label>
</ITEMTEMPLATE>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Status">
<HEADERSTYLEHorizontalAlign="Center">/HEADERSTYLE>
<ITEMSTYLEHorizontalAlign="Left"></ITEMSTYLE>
<ITEMTEMPLATE>
<asp:Label id="status" Visible="true" runat="server" Text='
'></asp:Label>
</ITEMTEMPLATE>
</asp:TemplateColumn>
</COLUMNS>
</asp:datagrid>
Our aim is to be able to localise the values of the column headings, the values defined by the headerText parameter of the asp:TemplateColumn tag.
To do this we add a reference to the localisation before we bind the datagrid.
Services.Localization.Localization.LocalizeDataGrid(grdListItem, Me.LocalResourceFile)
In this article I will consider the settings of the header text for the columns of a datagrid. Consider the following single column datagrid.
| Name |
Status |
| People |
Live |
| Pets |
Live |
| Restaurant |
|
| Pub |
|
<asp:datagrid id="grdListItem" Visible="False" OnPageIndexChanged="grdListItemPage" AllowPaging="True" bordercolor="transparent" Borderwidth="0" CellPadding="4" AutoGenerateColumns="False" runat="server" GridLines="None" width="400px">
<ALTERNATINGITEMSTYLEBackColor="Gainsboro"></ALTERNATINGITEMSTYLE>
<ITEMSTYLE BackColor="WhiteSmoke" Font-Size="10px" Font-Names= "Verdana"HorizontalAlign="Right"></ITEMSTYLE>
<HEADERSTYLECssClass="janetarticles_datagridheader"></HEADERSTYLE>
<PAGERSTYLE CssClass= "janetarticles_datagridPage"Mode="NumericPages"></PAGERSTYLE>
<COLUMNS>
<asp:TemplateColumnHeaderText= "Name">ITEMSTYLEHorizontalAlign="Left"></ITEMSTYLE>
<ITEMTEMPLATE>
<asp:Label id="id" Visible="False" runat="server" Text='
' NAME="id"></asp:Label>
<asp:Label id="name" runat="server" Text='
' NAME="name"></asp:Label>
</ITEMTEMPLATE>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Status">
<HEADERSTYLEHorizontalAlign="Center"></HEADERSTYLE>
<ITEMSTYLEHorizontalAlign="Left"></ITEMSTYLE>
<ITEMTEMPLATE>
<asp:Label id="status" Visible="true" runat="server" Text='
'></asp:Label>
< /ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
</COLUMNS>
</asp:datagrid>
Our aim is to be able to localise the values of the column headings, the values defined by the headerText parameter of the asp:TemplateColumn tag.
To do this we add a reference to the localisation before we bind the datagrid.
Services.Localization.Localization.LocalizeDataGrid(grdListItem, Me.LocalResourceFile)
Private Sub BindData(ByVal SearchText As String, ByVal SearchField As String)
Try
Services.Localization.Localization.LocalizeDataGrid(grdListItem, Me.LocalResourceFile)
Dim obj As New Info
Dim objs As New Controller
grdListItem.DataSource = objs.janetArticles_GetArticleList(ModuleId, PortalId, 0, "Edit0", 0, strFilter, "%" & Category & "%", 0)grdListItem.DataBind()
grdListItem.Visible = True
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Lastly in the loclaisation file associated with our ascx file, for example the file category_edit.ascx.en-GB.resx in the directory DesktopModules\janet.Articles\App_LocalResources add entries for each of the headings.
Note, for clarity, I have shown these entries in the XML view mode, rather than the default data mode.
<DATA name="Name.Header">
<VALUE>Name</VALUE>
</DATA>
<DATA name="Status.Header">
<VALUE>Status</VALUE>
</DATA>
NAT November 2005