473,396 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamic titles for datagrid columns

I need to build a multi-lingual application with asp.net. I do not want
to have a version of the application per language used. To achieve
this, I have recorded in my database all the labels and messages of my
application. It worked fine except that if I do my data binding at run
time and display dynamically the datagrid column header according to
the language selected, I loose all the features of the datagrid such as
sorting, paging, etc...

Should you have an idea to solve the problem in a way or another,
please let me know.

Best Regards

Patrick

Nov 19 '05 #1
1 1203
The norm for globalization and localization is resource files. I am not sure
how to do this with a DataGrid, but I am sure it has been tackled somewhere.

I this is not an option, you can always use the ItemDataBound event for the
DataGrid. Here is a small example:

VB.NET
--------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim ht As New Hashtable
ht.Add("0", "something")
ht.Add("1", "something else")

DataGrid1.DataSource = ht
DataGrid1.DataBind()
End Sub

Private Function GetHeader(ByVal x As Integer) As String
'Sample Only: Needs implementation that uses globalization
If (x = 0) Then
Return "ID"
Else
Return "Name"
End If
End Function

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As _
System.Web.UI.WebControls.DataGridItemEventArgs) Handles _
DataGrid1.ItemDataBound
If (e.Item.ItemType = ListItemType.Header) Then
For counter As Integer = 0 To e.Item.Cells.Count - 1
e.Item.Cells(counter).Text = GetHeader(counter)
Next counter
End If
End Sub

Assumes the following DataGrid:

<asp:DataGrid id="DataGrid1" runat="server" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4"
AutoGenerateColumns="False">
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="key" HeaderText="Header
Text"></asp:BoundColumn>
<asp:BoundColumn DataField="value" HeaderText="Header Text
2"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099"
BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>

Yes, it is inanely simple, but it illustrates how to hijack the form if you
cannot find a declarative way to accomplish globalization.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Patrick" wrote:
I need to build a multi-lingual application with asp.net. I do not want
to have a version of the application per language used. To achieve
this, I have recorded in my database all the labels and messages of my
application. It worked fine except that if I do my data binding at run
time and display dynamically the datagrid column header according to
the language selected, I loose all the features of the datagrid such as
sorting, paging, etc...

Should you have an idea to solve the problem in a way or another,
please let me know.

Best Regards

Patrick

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JP011 | last post by:
Hello I have hit a major road block when it comes to building my dynamic datagrid. To make a long story short I need a dynamic datagrid because my connection string could change and I need the...
0
by: javatopia | last post by:
I am creating a data grid's columns on the fly in my web page. The Bind operation works just fine, and data is displayed correctly when I change the layout of the grid (add/remove columns). I...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
0
by: tafpin | last post by:
I have an application with a datagrid. In the IDE I have 2 template columns. The first has an image button and the second contains a link button. According to the results that I get back I must...
7
by: CanoeGuy | last post by:
I have been trying for the last two weeks to display a dynamic DataGrid. The data that I'm pulling from a SQL Server DB will have whole columns that will be either NULL or 0. I want to display...
2
by: tshad | last post by:
I have a Datagrid that has no rows in it, but I want the title to show, and they aren't. Is there a way to make them visible even if the Datagrid is empty? Thanks, Tom
3
by: ER | last post by:
Hi, I would like to create a datagrid or free entry form with dynamic columns based on the user selection, do you have any ideas or samples? Any help would be appreciated! ER
0
by: KA NMC | last post by:
I have a dataGrid that is populated by SQL table. The Datagrid has two dynamic columns - that I created to for calculations. I want to sort the grid on frmload by one of the dynamic columns is that...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.