Loupi
Loupi

Reputation: 1112

Binding the selected value in ASP datepicker to formview in ASP.NET

I have a pop up date picker which insert a selected date into a textbox. My problem is that I cannot bind it to the asp.net textbox control. I'm currently following this but it shows an error "The name 'dateborrowedTextBox' does not exist in the current context". I want it to bind the selected value to a textbox in formview so I can add it to the database.

Here's a sample of my formview control Insert

<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 />

            <%--I want to the selected value in datepicker to bind it here --%>
            Date borrowed:
            <asp:TextBox ID="dateborrowedTextBox1" runat="server" 
                Text='<%# Bind("dateborrowed") %>' />

            <%--date picker --%>
            <input type="text" name="dateborrowedTextBox" readonly id="dateborrowedTextBox"> 
            <a href="#" onClick="cdp1.showCalendar(this, '<% = dateborrowedTextBox.ClientID %>'); 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>

Help would be much appreciated. Thanks in advance.

Upvotes: 1

Views: 2630

Answers (1)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Make your input control a server control by adding runat="server" to the control, and then use value property.

<input type="text" runat="server" value='<%# Bind("dateborrowed") %>' name="dateborrowedTextBox" readonly id="dateborrowedTextBox">

Upvotes: 2

Related Questions