asp.net - Dynamically insert date into gridview header -
i have gridview compares data between current year , last year.
<columns> <asp:boundfield datafield="st_entity_id" headertext="entity id" sortexpression="st_entity_id" /> <asp:boundfield datafield="totalconsentsthisyear" headertext="total consents year" readonly="true" sortexpression="totalconsentsthisyear" /> <asp:boundfield datafield="totalconsentslastyear" headertext="total consents last year" readonly="true" sortexpression="totalconsentslastyear" /> <asp:boundfield datafield="totalissuedconsentsthisyear" headertext="total issued consents year" readonly="true" sortexpression="totalissuedconsentsthisyear" /> <asp:boundfield datafield="totalissuedconsentslastyear" headertext="total issued consents last year" readonly="true" sortexpression="totalissuedconsentslastyear" /> <asp:boundfield datafield="totalinspectionsthisyear" headertext="total inspections year" readonly="true" sortexpression="totalinspectionsthisyear" /> <asp:boundfield datafield="totalinspectionslastyear" headertext="total inspections last year" readonly="true" sortexpression="totalinspectionslastyear" /> </columns>
however, gridview display total inspections 2014 instead of total inspections last year. know have use template field this, don't know how format achieve required result.
here's how did first column of grid view (adjust column want) :
protected void page_load(object sender, eventargs e) { string curheader = gridview1.headerrow.cells[0].text; gridview1.headerrow.cells[0].text = string.format("{0} {1}", curheader, datetime.now.addyears(-1).year); }
and result got:
Comments
Post a Comment