c# - format column (value) of datatable dynamically -


is possible format datatable column value @ runtime?

i'm trying show date inside datetime column below,

foreach (datacolumn c in ds.tables[0].columns) {     if (c.datatype == typeof(datetime))     {         string.format("mm/dd/yyyy", c);     } } 

but getting full date time..

edit :

till now, i'm upto this,..

 foreach (datarow dr in ds.tables[0].rows)      {      foreach (datacolumn dc in ds.tables[0].columns)         {          if (dc.datatype == typeof(datetime))             {              if (!string.isnullorempty(convert.tostring(dr[dc])))               {                //string s = dr[dc].tostring();                //dr[dc] = s.substring(0, s.indexof(' '));                //dr[dc] = convert.todatetime(dr[dc]).toshortdatestring();                dr[dc] = convert.todatetime(dr[dc]).tostring("mm/dd/yyyy");               }              }          }        } 

still not able desired result

got solution below,..

                    datatable dtcloned = ds.tables[0].clone();                     foreach (datacolumn c in ds.tables[0].columns)                     {                         if (c.datatype == typeof(datetime))                         {                             dtcloned.columns[c.columnname].datatype = typeof(string);                             colnames.add(c.columnname);                         }                     }                     foreach (datarow row in ds.tables[0].rows)                     {                         dtcloned.importrow(row);                     }                      foreach (datarow dr in dtcloned.rows)                     {                         foreach (datacolumn dc in dtcloned.columns)                         {                             if (colnames.contains(dc.columnname))                             {                                 string dt = convert.tostring(dr[dc]);                                 if (!string.isnullorempty(dt))                                 {                                     datetime date = datetime.parseexact(dt.substring(0, dt.indexof(' ')), "m/d/yyyy", system.globalization.cultureinfo.invariantculture);                                     dr[dc] = date.tostring("mm/dd/yyyy");                                 }                             }                         }                     } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -