c# - How to change date Culture of a dateTime in DataTable or from GridView? -


i have fields in database , 2 of them datetime field, retrieving via 'datatable' in gridview in below code

c# code

var connection = new mysqlconnection(_testmysqlconstring); string query1 = myquery; var cmd1 = new mysqlcommand(query1, connection); connection.open(); var datatable1 = new datatable(); var da1 = new mysqldataadapter(cmd1); da1.fill(datatable1); grdinvitationtenderslist.datasource = datatable1; grdinvitationtenderslist.databind(); 

asp code

<asp:gridview id="grdlist" runat="server"                 allowsorting="true" autogeneratecolumns="false"                 datakeynames="r_number" onrowcommand="grdlist_rowcommand" >                 <alternatingrowstyle backcolor="white" />  <columns> ....                       <asp:boundfield datafield="tender_number" headertext="t_number" readonly="true" sortexpression="t_number"  visible="true"></asp:boundfield>  <asp:boundfield datafield="last_date_submission" headertext="last date of submission" readonly="true" sortexpression="last_date_submission" headerstyle-borderstyle="solid"                         headerstyle-horizontalalign="right" footerstyle-backcolor="pink" footerstyle-bordercolor="white" visible="true" dataformatstring="{0:g}"></asp:boundfield> ......  </columns> 

last_date_submission datetime field.

my question how can have datetime in yyyy/mm//dd hh:mm:ss, have convert culture , display datetime in gridview

*edit 1: * i admit question not cleared. let me explain more, second part of question "i have convert datetime other calender type , display in gridview"

a datetime value doesn't have culture, inherently. it's value. suspect should change though:

dataformatstring="{0:g}" 

for example, change to:

dataformatstring="{0:yyyy/mm/dd hh:mm:ss}" 

(note hh rather hh, assuming want 24-hour view. likewise assume // in question typo.)

that's if want hard-code particular format. if want "whatever appropriate format culture" should make sure current culture correct while you're processing request, , original dataformatstring appropriate.

edit: i've seen wanting change calendar system - in case is making sure you're using right culture. datetime value doesn't have calendar system; calendar system determined culture it's displayed in.

an alternative use noda time library - convert value localdatetime whatever calendar want, can displayed independently of culture.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -