vb.net - DataFormatString not working with data grid -
i have format issue data grid. have applied formatting property adatacolumn.dataformatstring = "{0:d}"
private function createcolumnfromnode(byval adisplaypropertynode xmlnode) boundcolumn dim propertykey string = cxmldoc.attributetostring(adisplaypropertynode, "propertykey") dim columnheader string = configurabletext(cxmldoc.attributetostring(adisplaypropertynode, "columnheader")) if propertykey = "" return nothing dim adatacolumn new boundcolumn() adatacolumn.datafield = propertykey adatacolumn.headertext = iif(columnheader = "", propertykey, columnheader) <b> adatacolumn.dataformatstring = "{0:d}"</b> return adatacolumn end function
to data grid. while exporting excel takes default settings of system.
i have used following code exporting. not custom code.
it uses asp.net proprty.
dim response httpresponse = httpcontext.current.response response.clear() response.charset = "" ' set response mime type response.contenttype = "application/vnd.ms-excel" response.addheader("content-disposition", "attachment;filename=" + afilename) ' create string writer using sw system.io.stringwriter = new system.io.stringwriter() using htw htmltextwriter = new htmltextwriter(sw) ' instantiate datagrid datagrid1.rendercontrol(htw) response.write(sw.tostring()) end using end using response.end()
thanks..
i'd suggest reason you're getting default system settings when exporting excel because of excel's automatic cell formatting feature, @ cell 's value contents , automatically apply 1 of pre-defined formats unless specific format otherwise specified user override one.
as can't see excel export code i'll assume you're doing yourself, in case need add line code either set datetime format of column or else set format text. test open 1 of spreadsheets you've exported , change format of column text , see if gives original data back.
Comments
Post a Comment