【问题标题】:Binding the selected value in ASP datepicker to formview in ASP.NET将 ASP datepicker 中的选定值绑定到 ASP.NET 中的 formview
【发布时间】:2011-08-23 22:37:55
【问题描述】:

我有一个弹出日期选择器,可以将选定的日期插入文本框。我的问题是我无法将它绑定到 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>

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

【问题讨论】:

    标签: c# asp.net data-binding formview


    【解决方案1】:

    通过将runat="server" 添加到控件,使您的输入控件成为服务器控件,然后使用value property

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

    【讨论】:

    • 谢谢!它工作,但它仍然有一个错误。错误:“this._targetEl.value.length”为空或不是对象
    • 我认为这是与上述解决方案不同的错误。实施我的解决方案后,您是否遇到了这个问题?
    • 是的。当我不将它们绑定在一起时没有问题。我认为我有一些错误。我会检查
    • 顺便说一句,如果我可能会问有没有办法让我获得价值?我的意思是在输入类型 = 文本中如何获取值并将其传递给 asp:TextBox。
    • ((System.Web.UI.HtmlControls.HtmlInputText)detailsView1.FindControl("dateborrowedTextBox")).Value
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2011-01-14
    • 2012-05-02
    相关资源
    最近更新 更多