asp.net - 在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"
我的问题:最终输出没有显示日期,我在这里做错了什么?它只是显示一个空的文本框。此外,它不允许我编辑它。
解决方案
尝试使用 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>
推荐阅读
- c - 如何从字符串类型行中提取char类型元素并添加到c中的列表
- javascript - Javascript 在有效文件名后获取路径(如 PHP PATH_INFO)
- xampp - PWA - 与 Xampp 和虚拟主机一起使用时无法注册 Service Worker
- javascript - ugly nested forEach in javascript best practise
- jenkins-pipeline - Artifactory Continuous integration approach
- c++ - Syntax of an un-named function pointer in C++
- android - Android NDK - 无法在 Visual Studio 2017 中调试
- python - Python program that simulates a full one player game of pig, starting at a totalscore of 0 and playing turn after turn until it reaches 100 points
- c# - 将数据集序列化为 XML - 缺少具有空值的列
- python-2.7 - AttributeError:“Mul”对象没有属性“eval”