Reputation: 1112
I'm having some problem binding the value of a date picker to a textbox in formview asp.net. I've tried to a put a date picker in ASP.NET and JavaScript which calls on a class file in calendar.css so far it can display the date but if I tried to insert it to a record it always return null. So how can I bind it so it can add the date value to the record?
Help would be much appreciated.
Thanks in advance ;)
Here's a sample of my code. I want to bind the 'input text' to the 'dateborrowedTextBox'
<InsertItemTemplate>
Book Title:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="booktitleDataSource" DataTextField="booktitle"
DataValueField="bookid" SelectedValue='<%# Bind("bookid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="booktitleDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [bookid], [booktitle] FROM [TblBooks]">
</asp:SqlDataSource>
<br />
Employee PIN:
<asp:TextBox ID="employeeidTextBox" runat="server"
Text='<%# Bind("employeeid") %>' />
<br />
Department:
<asp:TextBox ID="departmentTextBox" runat="server"
Text='<%# Bind("department") %>' />
<br />
Date borrowed:
<%--<asp:TextBox ID="dateborrowedTextBox" runat="server"
Text='<%# Bind("dateborrowed") %>' />--%>
<input type="text" name="dateborrowedTextBox" readonly="readonly" id="dateborrowedTextBox">
<a href="#" onclick="cdp1.showCalendar(this, 'dateborrowedTextBox'); return false;">Date Picker
</a>
<br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
Upvotes: 0
Views: 1484
Reputation: 1112
Just found my answer. ASP.NET cant read Javascript normally so CT100 and some dollar sign will do the trick ;)
<a href="#" onclick="cdp1.showCalendar(this, 'ctl00$ContentPlaceHolder1$reservedateTextBox'); return false;">Date Picker</a>
Upvotes: 0
Reputation: 22332
The client-side IDs of the ASP.NET controls are not going to be translated as cleanly as you are hoping.
You need to do one of two things, both of which can be found here.
<a href="#" onclick="cdp1.showCalendar(this, '<%= dateborrowedTextBox.ClientID %>'); return false;">Date Picker</a>
Or, you could add a Link control and set the actions that way (the link I gave you does it with an image control). It's up to you.
Upvotes: 1