将 ASP datepicker 中的选定值绑定到 ASP.NET 中的 formview

发布于 2024-11-06 16:14:26 字数 2232 浏览 5 评论 0原文

我有一个弹出日期选择器,它将选定的日期插入文本框。我的问题是我无法将其绑定到 asp.net 文本框控件。我目前正在关注 this 但它显示错误“名称 ' dateborrowedTextBox' 在当前上下文中不存在”。我希望它将选定的值绑定到表单视图中的文本框,以便我可以将其添加到数据库中。

这是我的 formview 控件插入帮助的示例,

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

我们将不胜感激。 提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2024-11-13 16:14:26

通过向控件添加 runat="server" 使输入控件成为服务器控件,然后使用 value 属性

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

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">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文