sql - Gridview Calculated Field in Row -


i using visual studio 2010 , visual basic linked sql database. have gridview in want have calculated field, let's call nohoursoff, based on fields in row - begintimeoff , endtimeoff.

after doing research, learned should use templatefield. don't understand how works. have tried no success:

<asp:templatefield headertext="total hours" >         <itemtemplate>             <asp:label id="label1" runat="server" text='<%# "endtimeoff" - "begintimeoff" %>' width="100px"></asp:label>>             </itemtemplate>         </asp:templatefield> 

i have tried replacing text value "endtimeoff".subtract("begintimeoff") works on webpage. don't understand how calculated field! please or can direct me tutorial explain me.

you need create function in codebehind this

public string getvalue(object begintimeoff, object endtimeoff)     {         return (convert.todatetime(endtimeoff.tostring()) - convert.todatetime(begintimeoff.tostring())).tostring();     } 

and in label this

text=<%# getvalue(eval("begintimeoff"), eval("endtimeoff")) %> 

then set format want display in method (n days, hh.mm.ss, etc) fit requirement


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -