asp.net - Unable to format date in dataset column,GridView -


I am reading data from excel sheet and displaying it in data gridview. There are some date columns in Excel. When I read data from Excel and bind it in the DataGrid view. The date is displayed in the format "02/02/2009 12:00:00 AM" but the actual data in the Excel column "2/2/2009". So how to change the date format in DataAgrid view.

Since I'm bound data from the dataset so I do not set a template column or bound column so I do not know where set out HtmlEncode = "False" DataFormatString = "{0: T} "

Is there any way to do this? Please help me

Please find a sample of the code below.

  string OleDbConnection = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" + FileUpload1.PostedFile.FileName + ", extended attributes = \" Excel 8.0; HDR = yes, ex = 1 \ ""; String strSheetName = "Sheet1"; Oleandbankation olecognition; Olebub Commands Oleb Command; OlebeyDataAdaptatorOldAdapter; OledbCommand = New OleDbCommand (); OledbAdapter = New OleDbDataAdapter (); Dataset dsExcellData = new dataset (); OledbConnection = New OleDbConnection (OleDbConnection); OledbConnection.Open (); Oledb Commander. Connection = Oleb Connection; OledbCommand.CommandText = "[* + Choose from strSheetName +" $] "*; // I want to find oledbAdapter name of this paper. SelectionCommand = oledbCommand; oledbAdapter.Fill (dsExcellData); oledbConnection.Close (); GridView1.DataSource = DsExcellData.Tables [0]; GridView1.DataBind ();  

================================= ================================= I tried

dsExcellData.Tables [0]. Ross [Rukaunt] [ "Det_colm"]. Tostring ()] .. = Dseksselldataktebls [0] [Rukaunt] [ "Det_colm"] Tostring ()] Tostring ( "D") Kros;

But value is not being assigned as "dd / mm / yyyy" It is also taking time to default time (mm / day / yay hh: mm: ss am).

= ============ ===== ===========================================

The problem is that I am unable to change the data in the dataset format, in the data format, mm / dd / yyah hm: mm: ss is reading dat column.

=========================================== == =================================

Finili gave me an answer from ScottE: DataGride View:

  secure void dgValidatedData_ItemDataBound1 (object sender, DataGridItemEventArgs e) {for (int i = 0; I & lt; = E.Item.Cells.Count - 1; I ++) {System.DateTime cellDate = Default (System.DateTime); If (System.DateTime.TryParse (e.Item.Cells [i]. Text, out of salad)) {ITOM. Seals [i]. Text = string Format ("{0: d}", celadet); }}}}  

OK, try it, where the "item" column Name can be more than one) It is a date that requires formatting. This is definitely vb.net, but you can make it out like I'm sure there is a better way, but it works.

  Protected Sub gv_RowDataBound (ByVal) e.Row as this object, ByVal e System.Web.UI.WebControls.GridViewRowEventArgs. RowType = DataControlRowType.DataRow for the I = 0 e.Row.Cells.Count as integer - 1, so gv.HeaderRow.Cells (i) .text = "before" then e.Row.Cells (I) .text = string format ("{0: D}", CTP (E.O. Seals (I). Text, date)) If the ending ends, then sub  
< P> Or, if you do not know that the column dates will work well in the following form:

  protected subgv_RowDataBound (ByVal As the object, ByVal e System Web.UI.WebControls.GridViewRowEventArgs) B e .Row.RowType = DataControlRowType.DataRow then Ikrokkel = 0 as the integer I. Calculate - dated as 1 date dated. Trypers (E.O. Seals (i). Text, Sailet). Line. Seals (I). Text = string.format ("{0: d}", celadet) end if the next end if ending sub  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -