0

I have two different views in my ASP.Net application. I have a list view and a calendar view. I am trying to get the link to perform differently under certain circumstances. If the the class is full the link should be disabled and read class full. If there are available spots it should allow people to click on the link. If it is past the registration closed date of the class it should tell them that and not let them click on the link. Everything is working except the registration closed part. Here is my code for the list view. It is in a grid view:

listLink.NavigateUrl = "~/List.aspx?eventAuid=" + Request.QueryString["eventAuid"];
            monthlyCalendarLnk.NavigateUrl = "~/Calendar.aspx?eventAuid=" + Request.QueryString["eventAuid"];
           

            for (int a = 0; a < eventOccurrencesGV.Rows.Count; a++)
            {
                if (eventOccurrencesGV.Rows[a].Cells[7].Text == "0")
                {
                    eventOccurrencesGV.Rows[a].Cells[8].Text = "Class Full";
                }

                if (eventOccurrencesGV.Rows[a].Cells[2].Text < DateTime.Now)
                {
                    eventOccurrencesGV.Rows[a].Cells[8].Text = "Registration Closed";
                }
            }

Here is how the gridview is set up:

<asp:GridView ID="eventOccurrencesGV" runat="server" DataSourceID="listGridViewDS" AutoGenerateColumns="False"
        OnSelectedIndexChanged="eventOccurrencesGV_SelectedIndexChanged" CellPadding="4" ForeColor="#333333"
        GridLines="None">
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:BoundField DataField="eventAuid" HeaderText="eventAuid" ReadOnly="True" SortExpression="eventAuid"
                InsertVisible="False" Visible="False" />
            <asp:BoundField DataField="eventOccurrencesAuid" HeaderText="eventOccurrencesAuid"
                SortExpression="eventOccurrencesAuid" InsertVisible="False" ReadOnly="True" Visible="False" />
            <asp:BoundField DataField="eventRegistrationClosed" 
                SortExpression="eventRegistrationClosed" Visible="False" />
            <asp:BoundField DataField="dayOfWeek" HeaderText="Day Of Week" SortExpression="dayOfWeek"
                ReadOnly="True" />
            <asp:BoundField DataField="startDateTime" HeaderText="Start Date/Time" SortExpression="startDateTime" />
            <asp:BoundField DataField="endDateTime" HeaderText="End Date/Time" SortExpression="endDateTime" />
            <asp:BoundField DataField="location" HeaderText="Location" 
                SortExpression="location" />
            <asp:BoundField DataField="remainingSpots" HeaderText="Remaining Spots" SortExpression="remainingSpots">
            </asp:BoundField>
            <asp:HyperLinkField DataNavigateUrlFields="eventAuid,eventOccurrencesAuid" 
                DataNavigateUrlFormatString="SignUpForAnEventOccurrence.aspx?eventAuid={0}&amp;eventOccurrencesAuid={1}" 
                Text="Sign up" />
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>

Here is my code for the calendar view:

if (numberOfEventsForDay > 0)
            {
                e.Cell.Controls.Add(new LiteralControl(@"<span style=""text-align:center""><br />"));

                for (int i = 0; i < numberOfEventsForDay; i++)
                {
                    if (i > 0)
                    {
                        e.Cell.Controls.Add(new LiteralControl("<hr />"));
                    }
                    string regCloseDate = ds.Tables[0].Rows[i]["eventRegistrationClosed"].ToString();
                    string startDateTime = ds.Tables[0].Rows[i]["startDateTime"].ToString();
                    string endDateTime = ds.Tables[0].Rows[i]["endDateTime"].ToString();
                    string formatStartDateTime = DateTimeFormatting(startDateTime);
                    string formatEndDateTime = DateTimeFormatting(endDateTime);
                    string formatRegistrationClosed = DateTimeFormatting(endDateTime);
                    string eventOccurrencesAuid = ds.Tables[0].Rows[i]["eventRegistrationClosed"].ToString();
                    string location = ds.Tables[0].Rows[i]["location"].ToString();
                    string remainingSpots = ds.Tables[0].Rows[i]["remainingSpots"].ToString();

                    HyperLink eventHpl = new HyperLink();
                    eventHpl.Font.Size = FontUnit.Point(7);

                    if (int.Parse(remainingSpots) <= 0)
                    {
                        eventHpl.Text = formatStartDateTime + "-" + formatEndDateTime + " " + location + " (FULL)";
                    }
                    if (formatRegistrationClosed < DateTime.Now)
                    {
                        eventHpl.Text = formatStartDateTime + "-" + formatEndDateTime + " " + location + " (REGISTRATION CLOSED)";
                    }
                    else
                    {
                        eventHpl.Text = formatStartDateTime + "-" + formatEndDateTime + " " + location + " (" + remainingSpots + ")";
                        eventHpl.NavigateUrl = "SignUpForAnEventOccurrence.aspx?eventAuid=" + eventAuid + "&eventOccurrencesAuid=" + eventOccurrencesAuid;
                    }
                    
                    e.Cell.Controls.Add(eventHpl);
                    
                }

            }


            e.Cell.Controls.Add(new LiteralControl(@"</span>"));
        }

The error I am getting for both of these is:
"Operator '<' cannot be applied to operands of type 'string' and 'System.DateTime'"

I tried first to have string equal to DateTime.Now but that did not work either. So I do not know how to fix my issue. If anybody can help I would apprieciate it.

Thank you.

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by crishjeny
0

the error is very much clear..

you are trying to compare DateTime with string not possible..

one way possible if you convert string to DateTime using DateTime.Parse(YourString)

hope that helps

0

Thank you but I still get the same error when I add the DateTime.Parse.

0

Ok, so I did change the code to add datetime.parse and I can now build and rn the application. But when I try to go to the list view page I get this error:

Incorrect syntax near 'WeekDay'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 'WeekDay'.

Source Error:


Line 23:
Line 24:
Line 25: for (int a = 0; a < eventOccurrencesGV.Rows.Count; a++)
Line 26: {
Line 27: if (eventOccurrencesGV.Rows[a].Cells[7].Text == "0")


Source File: C:\Users\jdamisch\Documents\Visual Studio 2008\Projects\RSVPApplication\RSVPApplication\List.aspx.cs Line: 25

Here is what I changed my code to:

if (numberOfEventsForDay > 0)
            {
                e.Cell.Controls.Add(new LiteralControl(@"<span style=""text-align:center""><br />"));

                for (int i = 0; i < numberOfEventsForDay; i++)
                {
                    if (i > 0)
                    {
                        e.Cell.Controls.Add(new LiteralControl("<hr />"));
                    }
                    string regCloseDate = ds.Tables[0].Rows[i]["eventRegistrationClosed"].ToString();
                    string startDateTime = ds.Tables[0].Rows[i]["startDateTime"].ToString();
                    string endDateTime = ds.Tables[0].Rows[i]["endDateTime"].ToString();
                    string formatStartDateTime = DateTimeFormatting(startDateTime);
                    string formatEndDateTime = DateTimeFormatting(endDateTime);
                    string formatRegistrationClosed = DateTimeFormatting(endDateTime);
                    string eventOccurrencesAuid = ds.Tables[0].Rows[i]["eventOccurrencesAuid"].ToString();
                    string location = ds.Tables[0].Rows[i]["location"].ToString();
                    string remainingSpots = ds.Tables[0].Rows[i]["remainingSpots"].ToString();

                    HyperLink eventHpl = new HyperLink();
                    eventHpl.Font.Size = FontUnit.Point(7);

                    if (int.Parse(remainingSpots) <= 0)
                    {
                        eventHpl.Text = formatStartDateTime + "-" + formatEndDateTime + " " + location + " (FULL)";
                    }
                    if (DateTime.Parse(formatRegistrationClosed) < DateTime.Now)
                    {
                        eventHpl.Text = formatStartDateTime + "-" + formatEndDateTime + " " + location + " (REGISTRATION CLOSED)";
                    }
                    else
                    {
                        eventHpl.Text = formatStartDateTime + "-" + formatEndDateTime + " " + location + " (" + remainingSpots + ")";
                        eventHpl.NavigateUrl = "SignUpForAnEventOccurrence.aspx?eventAuid=" + eventAuid + "&eventOccurrencesAuid=" + eventOccurrencesAuid;
                    }
                    
                    e.Cell.Controls.Add(eventHpl);
                    
                }

I do not understand the error Incorrect syntax near 'WeekDay'.??????? Please help.

0

Ignore the above error I fixed that...the error I am getting noe is on this part:

if (DateTime.Parse(eventOccurrencesGV.Rows[a].Cells[2].Text) < DateTime.Now)                {                    eventOccurrencesGV.Rows[a].Cells[8].Text = "Registration Closed";                }

which is part of the very first code I posted. The error I am getting is "String was not recognized as a valid datetime" I added the datetime.parse as suggested but it is not working. I did work on the calendar view but not for the gridview. ANy suggestions please?

0

Ok, it's all because that column is not visible in my gridview. If I make it visible the code works, but I do not want it visible, so I will continue looking for an answer, but if anybody else can help please let me know. Thank you.

0

I figured it out, I made the row visible but on my rowcreated event I made it invisible to that it would get the data first and then make the row invisiable. Thank you everyone for your help.

0

Hi..

To solve the issue of DateTime.Now function in ASP.Net/C#.You can refer the following code.It will help you.

Example ::

<script type="text/javascript">

alert('<%= System.DateTime.Now.ToString() %>');

</script>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.