Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2013, 08:55 AM
jmt jmt is offline
Registered User
 
Join Date: Jun 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculation on gridview field

I have a gridview that holds, among other things, a date which is pulled from a SQL db. How do I add a column after that date to the gridview which basically populates with either "expired" or "not expired" depending on if that date is past today's date or not? This column would appear with the rest of the data on page load. I've searched for examples like this and can't find anything close. Any help or a link to instruct how to do this is appreciated!
 
Old November 3rd, 2013, 11:11 AM
Authorized User
 
Join Date: May 2013
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
Default populating gridview

I did have the same issue, how to populate something from gridview and ended using listview :
Code:
 protected void ListView1_DataBound(object sender, EventArgs e)
    {
        if (RecordOK == true) ((Label)ListView1.InsertItem.FindControl("RecordIdLabel")).Text = recordNumber.ToString();      
    }
Success,
Erik
 
Old January 15th, 2014, 05:16 AM
EricCulbertson
Guest
 
Posts: n/a
Default

i too want to get it sorted and looking closely to the thread .. expecting some apt suggestions to turn in favour sooner than later
 
Old February 5th, 2014, 01:40 AM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Unhappy

If this is a design time gridview then just add databond column that has binding expression that test the date i.e.
Code:
<%# ((DataItemType)Container.DataItem).DateFieldProperty > SomeDate ? "Expired" : "Not Expired" %>
Where DataItemType is the type of your data item
DateFieldProperty is the property of a DateTime object in your data item
SomeDate is a DateTime object item to test against


You can also do this behavior in code, add the column in the load event, set the value of the column in the data bound event base on what the DataItem





Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView Template Field ktpatel ASP.NET 2.0 Professional 0 January 21st, 2009 10:07 AM
Replace Gridview field if null with new field Indo77 ASP.NET 2.0 Basics 1 June 18th, 2007 06:22 AM
Using Hyperlink field in GridView asp_convert ASP.NET 2.0 Basics 2 February 7th, 2007 07:33 PM
"Indent" field in gridview template. wirerider ASP.NET 2.0 Basics 0 March 1st, 2006 12:15 AM
Field Calculation Upgrade to VBA from Access Basic Pavesa Access VBA 2 December 23rd, 2003 12:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.