vb.net - How set Column format in GridView RowDataBound DataRow -


i have gridview , in rowdatabound event trying set format of column "dd mmm yyyy". first check if rowtype datarow, code shown below :

        if e.row.rowtype = system.web.ui.webcontrols.datacontrolrowtype.datarow         dim colcount integer         colcount = e.row.cells.count          looper = 0 colcount - 1              dim cell tablecell = e.row.cells(looper)             ' have hardcoded table name             dim temptabname string = "staff"             dim tempcolname string             dim tempcoltype string              dim currcol boundfield = directcast(directcast(e.row.cells(looper), datacontrolfieldcell).containingfield, boundfield)             ' extracting column name             tempcolname = currcol.headertext             ' extracting column type (varchar, datetime etc)             tempcoltype = getcoltype(temptabname, tempcolname)              ' depending on column type set format             ' depending on column type set format             select case tempcoltype                 case "varchar"                     status.text = "we @ varchar"                 case "nvarchar"                     status.text = "we @ nvarchar"                 case "char"                     status.text = "we @ char"                 case "datetime"                     status.text = "we @ datetime"                     currcol.dataformatstring = "{0:dd/mm/yy}"                                     case "date"                     status.text = "we @ date"                 case "time"                     status.text = "we @ time"                 case "float"                     status.text = "we @ float"             end select         next     end if 

when run code on line currcol.dataformatstring error "exception of type 'system.notsupportedexception' occurred in system.web.dll not handled in user code". additional info: specified method not supported

can please tell me doing wrong? or can please explain sample code of how achieve same?

you can direct set date format in gridview html markup.

if using itemtemplate sample code looks

  <asp:gridview id="gridview1" runat="server">     <columns>     <asp:templatefield>       <itemtemplate>            <asp:label             id="label1"             runat="server"             text='<%# databinder.eval(container.dataitem, "date_of", "{0:dd mmm yyyy}") %>'>         </asp:label>        </itemtemplate>     </asp:templatefield>     </columns>  </asp:gridview> 

here date_of if column name, want format


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -