首页 > 解决方案 > 在asp.net的文本框中绑定默认文本

问题描述

我正在尝试创建一个数据绑定文本框,该文本框必须显示从后端数据库中的关系中获取的默认字符串值。这是一个 ASP.NET Web 表单应用程序。还希望用户能够写入该文本框并更改我想要写enter code here回数据库的默认值。我在类后面使用代码,这里是我的 .aspx 页面的相关内容:

我在 Page_load 方法中初始化变量,作为中间实现,我对一些日期进行了硬编码。一旦我得到这个工作,我将使用 LINQ 来处理一个简单的查询并相应地填充这些类属性:

我在类后面使用代码,这里是我的 .aspx 页面的相关内容:

<div class="content" style="text-align: center">
    <p>The following are the default start and end dates. Change if inappropriate</p>
    <p> <asp:TextBox ID="StartDate" runat="server" Text=Bind("Dates.startDate") Enabled="false"></asp:TextBox> </p>    
    <p> <asp:TextBox ID="EndDate" runat="server" Text='<%# Bind("Dates.endDate")%>' Enabled="false"></asp:TextBox> </p>    
</div>

下面是类 .aspx.vb 后面的代码内容: 公共类日期

    Public Property startDate() As String
        Get
            Return m_startDate
        End Get
        Set(value As String)
            m_startDate = value
        End Set
    End Property
    Private m_startDate As String

    Public Property endDate() As String
        Get
            Return m_endDate
        End Get
        Set(value As String)
            m_endDate = value
        End Set
    End Property
    Private m_endDate As String
End Class

我在 Page_load 方法中初始化变量,作为中间实现,我对一些日期进行了硬编码。一旦我得到这个工作,我将使用 LINQ 来处理一个简单的查询并相应地填充这些类属性:

Dim Dates As New Dates()
Dates.startDate = "2019-01-01"
Dates.endDate = "2019-01-02"

我的问题:最终输出没有显示日期,我在这里做错了什么?它只是显示一个空的文本框。此外,它不允许我编辑它。

标签: asp.net

解决方案


尝试使用 Jquery 创建一个带有 DatePicker 的文本框

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

    <script>
        $(function () {
            $("#txtsdate").datepicker({
                defaultDate: "+1w",
                changeMonth: true,
                onClose: function (selectedDate) {
                    $("#txtedate").datepicker("option", "minDate", selectedDate);
                }
            });

        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Start Date:<asp:TextBox ID="txtsdate" runat="server"></asp:TextBox>
        </div>
    </form>
</body>
</html>

推荐阅读