Click here to Skip to main content
15,944,390 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Welcome everyone. Multilingual drop-down menu added. English and Arabic languages ​​have been added and are working properly. I want a datagrid to do the same thing using Resource.resx and I don't know the code.

What I have tried:

VB.NET
  1  Imports System.Threading
  2  Imports System.Globalization
  3  Imports System
  4  Imports System.Data
  5  Imports System.Data.SqlClient
  6  Imports System.Configuration
  7  Imports System.Web
  8  Imports System.Web.Configuration
  9  Imports System.Web.Security
 10  Imports System.Collections
 11  Imports System.IO
 12  
 13  Public Class BasePage
 14      Inherits System.Web.UI.Page
 15      Protected connStr = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
 16  
 17      Protected WithEvents lblout As System.Web.UI.WebControls.Label
 18      Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
 19      Protected WithEvents DataGrid2 As System.Web.UI.WebControls.DataGrid
 20      Protected WithEvents lblUser As System.Web.UI.WebControls.Label
 21      Protected WithEvents Label1 As System.Web.UI.WebControls.Label
 22      Protected WithEvents Label2 As System.Web.UI.WebControls.Label
 23      Protected WithEvents ddlLanguages As System.Web.UI.WebControls.DropDownList
 24      Protected Connection = New SqlConnection(connStr)
 25  
 26      Protected Overrides Sub InitializeCulture()
 27          Dim language As String = "en-us"
 28  
 29          'Detect User's Language.
 30          If Request.UserLanguages IsNot Nothing Then
 31              'Set the Language.
 32              language = Request.UserLanguages(0)
 33          End If
 34  
 35          'Check if PostBack is caused by Language DropDownList.
 36          If Request.Form("__EVENTTARGET") IsNot Nothing AndAlso Request.Form("__EVENTTARGET").Contains("ddlLanguages") Then
 37              'Set the Language.
 38              language = Request.Form(Request.Form("__EVENTTARGET"))
 39          End If
 40  
 41          'Set the Culture.
 42          Thread.CurrentThread.CurrentCulture = New CultureInfo("AR-SA")
 43          Thread.CurrentThread.CurrentUICulture = New CultureInfo(language)
 44  
 45      End Sub
 46      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 47  
 48          If Session.Contents("name") = "" Then
 49              lblout.Visible = True
 50              lblout.Text = "User Session Expired, please Login again...."
 51          Else
 52              lblout.Visible = False
 53              lblUser.Text = Session.Contents("name")
 54  
 55              BINDSEC()
 56              BindTime()
 57          End If
 58          If Not Me.IsPostBack Then
 59              If ddlLanguages.Items.FindByValue(CultureInfo.CurrentCulture.Name) IsNot Nothing Then
 60                  ddlLanguages.Items.FindByValue(CultureInfo.CurrentCulture.Name).Selected = True
 61              End If
 62          End If
 63      End Sub
 64      Dim ULOCATION, UCOUNTER, REPORTLOCATION
 65      Sub BINDSEC()
 66          Dim Connection As New SqlConnection(connStr)
 67          Dim adapter As New SqlDataAdapter("SELECT location,Counter,REPORTLOCATION from [hrusers] where userid='" & Session.Contents("name") & "'", Connection)
 68          Dim ds As New DataSet()
 69          adapter.Fill(ds, "tran")
 70          ULOCATION = ds.Tables("tran").Rows(0).Item("LOCATION")
 71          UCOUNTER = ds.Tables("tran").Rows(0).Item("COUNTER")
 72          REPORTLOCATION = ds.Tables("tran").Rows(0).Item("REPORTLOCATION")
 73      End Sub
 74      Sub BindTime()
 75          Dim Connection As New SqlConnection(connStr)
 76          'Dim adapter As New SqlDataAdapter("SELECT MEALTYPE as bio, CONVERT(varchar, STARTTIME, 109) AS StartTime, CONVERT(varchar, ENDTIME, 109) AS CloseTime,status,Mtype FROM A_MEALTIME WHERE Status='Y' and  STARTTIME <  GETDATE()   AND ENDTIME >  GETDATE()", Connection)
 77          'Dim ds As New DataSet()
 78          'adapter.Fill(ds, "head")
 79          'If ds.Tables("head").Rows.Count <> 0 Then
 80          Dim adapter4 As New SqlDataAdapter("SELECT MEALTYPE, CONVERT(varchar, STARTTIME) AS StartTime, CONVERT(varchar, ENDTIME) AS CloseTime,status,Mtype FROM A_MEALTIME WHERE Status='Y' and  STARTTIME <  GETDATE()   AND ENDTIME >  GETDATE() ", Connection)
 81          Dim ds4 As New DataSet()
 82          adapter4.Fill(ds4, "head4")
 83          DataGrid2.DataSource = ds4.Tables("head4").DefaultView
 84          DataGrid2.DataBind()
 85          If ds4.Tables("head4").Rows.Count <> 0 Then
 86              DataGrid2.Visible = True
 87              Label1.Visible = True
 88          Else
 89              DataGrid2.Visible = False
 90              Label1.Visible = False
 91  
 92          End If
 93          'Else AND REPORTLOCATION='" & REPORTLOCATION & "'
 94          Dim adapter2 As New SqlDataAdapter("SELECT MEALTYPE, CONVERT(varchar, STARTTIME, 108) AS StartTime, CONVERT(varchar, ENDTIME, 108) AS CloseTime,Status,'Normal' as Type FROM MEALTIME WHERE  Status='Y' AND REPORTLOCATION ='" & REPORTLOCATION & "' and      (CONVERT(varchar, STARTTIME, 108) < CONVERT(varchar, GETDATE(), 108)) AND (CONVERT(varchar, ENDTIME, 108) > CONVERT(varchar, GETDATE(),108)) ", Connection)
 95          Dim ds2 As New DataSet()
 96          adapter2.Fill(ds2, "tran2")
 97          DataGrid1.DataSource = ds2.Tables("tran2").DefaultView
 98          DataGrid1.DataBind()
 99          'End If
100  
101  
102          If ds2.Tables("tran2").Rows.Count <> 0 Then
103              DataGrid1.Visible = True
104              Label2.Visible = True
105          Else
106              DataGrid1.Visible = False
107              Label2.Visible = True
108          End If
109  
110      End Sub
111  
112  End Class
Posted
Updated 15-Nov-23 2:33am
v2
Comments
vblover Programmer 18-Nov-23 20:19pm    
you can make 2 datatable contains each language contents, then change dataset by language name...

1 solution

You cannot change the language of the data in the grid.

Languages in app resources only change the language of UI elements. You have to supply translations of stuff like messages and label text your app uses. Stuff that's part of your application when you write it.

Resources cannot be used to change the language of the data the app takes as input or displays. You cannot take data as input in English and expect the app to translate that data to show it in Arabic.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900