Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Evening folks,
Need some help and hopefully there are some smarter ones here.

Basically, I need a date picker in a formview on an ASP.net C# page.

This is what I have come up with so far but just can't seem to get things to work correctly.

<asp:FormView ID="KeyDates_FV" runat="server" CellPadding="4" DataKeyNames="ID" DataSourceID="KeyDates_SQL" ForeColor="#333333" GridLines="Both" OnDataBound="KeyDates_FV_DataBound">
<edititemtemplate>
LAA_PlanDate:
<asp:TextBox ID="LAA_PlanDateTextBox" runat="server" Text='<%# Bind("LAA_PlanDate") %>' />
<asp:Calendar ID="LAA_PlanDate_CAL" runat="server" ForeColor="White" >

<asp:ImageButton ID="LAA_PlanDate_IMB" runat="server" ImageAlign="Bottom" ImageUrl="~/Images/Calendar_icon.png" Width="16px" />

What I have tried:

Thank you in advance for any help on this.
Posted
Updated 8-Nov-18 11:21am
Comments
CHill60 7-Nov-18 4:01am    
You need to explain to us what the problem is. "can't seem to get things to work correctly" is too vague.
F-ES Sitecore 7-Nov-18 4:41am    
I'd probably start by looking at the documentation and examples, your mark-up for the calendar doesn't look valid

https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.calendar?view=netframework-4.7.2
Rob Howard 7-Nov-18 10:07am    
Thanks for the responses!
On the vague response, sorry about that, it was late a night and I was ready to hit the hay.
I have a form view on a page that will be displaying a date as a label under the <itemtemplate> for the form view. That works great. But when I click the Edit link on the form view, I'd like to have a small calendar image that would be clicked and calendar would appear. Once the calendar appears, you would be able to select the date and that date would populate into a text box.

The calendar mark up was just a calendar that I threw in the form view. Nothing really special with the calendar as of yet. I thought I'd try to tackle the harder bit first.

Mind you, I have been able to create a date picker before outside of a form view. But it seems that once I put the same date picker code (different page) into the form view, the form view barks at me. (Object reference not set to an instance of an object).

I've made a small change (see below) to the code and added the CS side as well.

FormView
<asp:FormView ID="KeyDates_FV" runat="server" CellPadding="4" DataKeyNames="ID" DataSourceID="KeyDates_SQL" ForeColor="#333333" GridLines="Both" OnDataBound="KeyDates_FV_DataBound">
<edititemtemplate>
LAA_PlanDate:
<asp:TextBox ID="LAA_PlanDateTextBox" runat="server" Text='<%# Bind("LAA_PlanDate") %>' />
<asp:Calendar ID="LAA_PlanDate_CAL" runat="server" ForeColor="White" Visible="false">
<asp:ImageButton ID="LAA_PlanDate_IMB" runat="server" ImageAlign="Bottom" ImageUrl="~/Images/Calendar_icon.png" Width="16px" OnClick="LAA_PlanDate_IMB_Click" />

CS page
protected void LAA_PlanDate_IMB_Click(object sender, ImageClickEventArgs e)
{
Calendar LAA_PlanDate_CAL = (Calendar)FormView1.FindControl("LAA_PlanDate_CAL");
LAA_PlanDate_CAL.Visible = true;
}

Thank you again for the help in advance!

Quote:
the form view barks at me. (Object reference not set to an instance of an object).


Your FormView ID was set to "KeyDates_FV" and in your code, you are using FormView1.FindControl("LAA_PlanDate_CAL");

FormView1 doesn't exist in the first place. So you want to do something like this instead:

C#
Calendar LAA_PlanDate_CAL = (Calendar)KeyDates_FV.FindControl("LAA_PlanDate_CAL");
 
Share this answer
 
Facepalm! Facepalm! Facepalm!

@Vincent Maverick THANK YOU SOOO MUCH! I feel like the hind end of a cows rear. I have been banging my head on the desk for two weeks to figure this out.

Thank you! Thank you! Thank you!
 
Share this answer
 
Comments
Richard Deeming 9-Nov-18 8:25am    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution. DO NOT post your reply as a new "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900