Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:16:55+00:00 2026-06-17T04:16:55+00:00

Let’s say I have a basic asp.net C# web app where I enter the

  • 0

Let’s say I have a basic asp.net C# web app where I enter the dates of different events, say oil changes, for example. And I want to track this for different vehicles. And then I want to calculate the difference in days between oil changes.

So for the most recent oil change, the datediff/timespan would calculate from today. But for previous oil changes, I want the datediff/timespan to calculate between each previous record in the recordset. I could, I suppose, create a field to put the number of days in there, but I think it should be easy to do programmatically, no?

Now, in classic ASP, I’d do something like this (in fact, this is what I do in the previous version of this little app):

<%set rs=conn.Execute("select vehiclename,changedate from oilchange order by changedate desc")
do until rs.EOF
dim recordchk,record
recordchk = record
date2=date1
date1=rs("changedate")
if record <> rs("vehcilename") then
record = rs("vehiclename")

end if%>

<%
if record <> recordchk then  
%>


<tr><td colspan="9"><hr color="black"/></td></tr>

<tr><td colspan="9"><b><%=rs("vehiclename") %></b></td></tr>
<tr><td valign="top" width="15%"><%=rs("changedate") %>&nbsp;<i>(<%=datediff("d",rs("changedate"),date()) %> days)</i></td>
</tr>

<%else%>

<tr><td valign="top" width="15%"><%=rs("changedate") %>&nbsp;<i>(<%=datediff("d",rs("changedate"),date2) %> days)</i></td>
</tr>

<%end if%>

<%rs.MoveNext
loop
rs.Close
%>

But I’m stumped how to do in in ASP.NET

For the different vehicles I have a repeater, then I nest a repeater inside to run through the oil change records for that vehicle. Runs through the list of oil changes just fine, but I can’t figure out how to do the calculation to get me the days between oil changes.

So, here’s my codebehind… (you can see that it’s not oil changes, but guitar string changes.)

protected void guitarrepeateritemdatabound(object sender, RepeaterItemEventArgs e)
    {
        stringsEntities db = new stringsEntities();

        if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            Repeater StringChangeRepeater = (Repeater)e.Item.FindControl("StringChangeRepeater");

            HiddenField guitarIDfield = (HiddenField)e.Item.FindControl("guitarIDint");
            int guitarIDint = Convert.ToInt32(guitarIDfield.Value);
            Label changedate = (Label)e.Item.FindControl("changedate");

            TimeSpan timeBetweenChanges = (DateTime.Now - Convert.ToDateTime(changedate));



            var qrystringchangesview = (from s in db.stringchange_view
                                        where s.guitarid == guitarIDint
                                        orderby s.changedate descending
                                        select new
                                        {
                                            guitarID2 = s.guitarid,
                                            s.guitarname,
                                            s.stringname,
                                            s.changedate,
                                            s.gauge

                                        });

            StringChangeRepeater.DataSource = qrystringchangesview;
            StringChangeRepeater.DataBind();

and then my aspx page:

 <asp:Repeater ID="GuitarRepeater" runat="server"  OnItemDataBound="guitarrepeateritemdatabound">
<ItemTemplate>
 <tr>
  <td valign="top">
  <asp:HiddenField ID="guitarIDint" runat="server" Value='<%# Eval("guitarID") %>' />

   <asp:LinkButton OnClick="clicktheinstrument" ID="guitarname" runat="server" Font-Bold="true" CommandArgument='<%#Eval ("guitarID") %>' Text='<%# Eval("guitarname") %>' />

   <asp:Repeater runat="server" ID="StringChangeRepeater">
    <ItemTemplate>
    <table><tr><td style="width:100px">
    <asp:Label ID="changedate" runat="server" Text='<%# Eval("changedate","{0:MM/dd/yyyy}") %>'></asp:Label> 
      (<asp:Label ID="timeBetweenChangesLabel" runat="server"></asp:Label>)
       </td><td style="width:200px">
       <asp:Label ID="stringname" runat="server" Text='<%# Eval("stringname") %>'></asp:Label>
       </td><td style="width:100px">
       <asp:Label ID="gauge" runat="server" Text='<%# Eval("gauge") %>'></asp:Label>
       </td></tr></table>
      </ItemTemplate>
      </asp:Repeater>
       </td>
      </tr>
       </ItemTemplate>
       <AlternatingItemTemplate>
       <tr style="background-color: #F7F7F7">
       <td valign="top">
       <asp:HiddenField ID="guitarIDint" runat="server" Value='<%# Eval("guitarID") %>' />

       <asp:LinkButton OnClick="clicktheinstrument" ID="guitarname" runat="server" Font-Bold="true" CommandArgument='<%#Eval ("guitarID") %>' Text='<%# Eval("guitarname") %>' />

       <asp:Repeater runat="server" ID="StringChangeRepeater">
       <ItemTemplate>
       <table><tr><td style="width:100px">
       <asp:Label ID="changedate" runat="server" Text='<%# Eval("changedate","{0:MM/dd/yyyy}") %>'></asp:Label>
       (<asp:Label ID="timeBetweenChangesLabel" runat="server"></asp:Label>)
       </td><td style="width:200px">
      <asp:Label ID="stringname" runat="server" Text='<%# Eval("stringname") %>'></asp:Label>
       </td><td style="width:100px">
       <asp:Label ID="gauge" runat="server" Text='<%# Eval("gauge") %>'></asp:Label>
       </td></tr></table>
        </ItemTemplate>
        </asp:Repeater>
        </td>
        </tr>
       </AlternatingItemTemplate>
        </asp:Repeater>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:16:56+00:00Added an answer on June 17, 2026 at 4:16 am

    well, I got an answer over at asp.net forums… thought I’d post it here to help anyone else who’s doing a similar thing.

    foreach (RepeaterItem item in StringChangeRepeater.Items)
                {
                    if (item.ItemType == ListItemType.Item || (item.ItemType == ListItemType.AlternatingItem))
                    {
                        HiddenField stringchangeIDHidden = item.FindControl("stringchangeID") as HiddenField;
                        int stringchangeID = Convert.ToInt32(stringchangeIDHidden.Value);
    
                        var getcurrentrecord = (from s in db.stringchange_view
                                                where s.ID == stringchangeID
                                                select new
                                                {
                                                    s.changedate
    
                                                }).First();
    
    
                        Label timeBetweenChangesLabel = item.FindControl("timeBetweenChangesLabel") as Label;
                        DateTime changedate1 = Convert.ToDateTime(getcurrentrecord.changedate);
                        TimeSpan changedateSpan = changedateX - changedate1;
                        TimeSpan changedateSpan2 = changedate1 - Convert.ToDateTime(getcurrentrecord.changedate);
                        timeBetweenChangesLabel.Text = changedateSpan.Days.ToString();
    
                        changedateX = changedate1;
    
    
    
                    }
    
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this element for displaying the website logo: <div id="web-title"> <a
Let's say I have to use an ASP master page and setup a Kendo
Let's say I have a user enter the URL of an image. After URL
Let's say you have different settings in development vs. production ( different options, different
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in
Let me explain best with an example. Say you have node class that can
Let's say I have a table with a Color column. Color can have various

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.