如何通过asp.net(access数据库)OLEDB命令获取输入(日期)并将其值插入到“文本框”中

5kgi1eie  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(400)

我在editinfo页面上工作,我做了一个mysql命令,将您登录到站点的帐户的数据插入到文本框中。
所有文本框都是asp.net,例如:asp:listitem
但现在我使用的是输入日期,我真的不知道如何插入它。

<tr>
            <td class = "textstyle">
                שם פרטי:
               </td>                
            <td class="style3">
                <asp:TextBox name = "fname" ID="firstname" runat="server" placeholder = "השם הפרטי שלך"></asp:TextBox>
            </td>
            </tr>
        <tr>
            <td class = "textstyle">
                שם משפחה:</td>
            <td class="style3">
               <asp:TextBox name = "lname" ID="lastname" runat="server" placeholder = "שם המשפחה שלך"></asp:TextBox>
            </td>
        </tr>
                    <td class = "textstyle">
               אזור מגורים:
               </td>                
            <td class="style3">
                <asp:DropDownList ID="PlaceList" runat="server">
                    <asp:ListItem disable hidden>בחר אזור</asp:ListItem>
                    <asp:ListItem id = "OurPlace">המרכז</asp:ListItem>
                    <asp:ListItem id = "OurPlace2">השרון</asp:ListItem>
                    <asp:ListItem id = "OurPlace3">הצפון</asp:ListItem>
                    <asp:ListItem id = "OurPlace4">הדרום</asp:ListItem>
                    <asp:ListItem id = "OurPlace5">ירושלים והסביבה</asp:ListItem>
                </asp:DropDownList>
        <tr>
            <td class = "textstyle">
                תאריך לידה:</td>
            <td class="style3">
            <input id="date" name = "date" type="Date" min="1905-01-01" max="2019-01-01" value="2018-01-01"/>
                    </td>
        </tr>
        <tr>
            <td class = "textstyle"">
                מין:</td>
            <td class="style3">
                    <input type = "radio" name="gender" id = "gender1" value ="זכר" /> <div class = "textstyle">זכר</div>
                    <input type = "radio" name="gender" id = "gender2" value ="נקבה" /> <div class = "textstyle">נקבה</div>
                    <input type = "radio" name="gender" id = "gender3" value ="אחר" /> <div class = "textstyle">אחר</div>
            </td>
        </tr>
        <tr>
            <td class = "textstyle">
                אימייל:</td>
            <td class="style6">
                <asp:TextBox name="email1" ID="MyEmail" runat="server" placeholder = "כתובת האימייל שלך"></asp:TextBox>
                        <tr><asp:Label ID="IsEmail" runat="server" Font-Names="arial" ForeColor="Red" Width="70px" Font-Size="Medium"></asp:Label></tr>
            </td>
        </tr>
        <tr>
            <td class = "textstyle">
                סיסמה:</td>
            <td class="style3">
                <asp:TextBox type = "password" name = "password" id="pass" runat="server" placeholder = "הסיסמה שלך"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class = "textstyle">
              אימות סיסמה:</td>
            <td class="style3">
                <asp:TextBox type = "password" name = "passwordchecker" ID="passchecker" runat="server" placeholder = "חזור שנית"></asp:TextBox>
            </td>
        </tr>

editinfo.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["User"] == null)
    {
        Response.Redirect("Home.aspx");
    }
    if ((Session["AdminMode"] == "1") || (Session["AdminMode"] == "2"))
        UserName = Session["AdminEditUser"].ToString();
    else
        UserName = Session["User"].ToString();
    if (!IsPostBack)
    {
        string connectionStr = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|\DataBase.mdb";
        OleDbConnection connectObj = new OleDbConnection(connectionStr);
        string mySql = "SELECT * from Users WHERE userName= '" + UserName + "'";
        OleDbDataAdapter dataAdapt = new OleDbDataAdapter(mySql, connectObj);
        DataSet ds = new DataSet();
        dataAdapt.Fill(ds, "users");
        DataRow row = ds.Tables["users"].Rows[0];
        pass.Text = row[1].ToString();
        passchecker.Text = row[1].ToString();
        firstname.Text = row[2].ToString();
        lastname.Text = row[3].ToString();
        MyEmail.Text = row[4].ToString();
        PlaceList.Text = row[5].ToString();
    }
}

问题图片-单击此处

tez616oj

tez616oj1#

其他html控件id在代码隐藏中找到,只需在html代码中添加runat=“server”。

<tr>
            <td class = "textstyle">
                תאריך לידה:</td>
            <td class="style3">
            <input id="date" name = "date" runat="server" type="Date" min="1905-01-01" max="2019-01-01" value="2018-01-01"/>
                    </td>
        </tr>

添加保存值的屏幕快照:


.aspx页面在日期文本框中添加绑定值的屏幕快照:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script lang="JavaScript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            debugger;
            var today = document.getElementById("hdDate").value;
            document.getElementById("date").value = today;
        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input id="date" name="date" runat="server" type="Date" min="1905-01-01" max="2019-01-01" value="" />
            <asp:HiddenField ID="hdDate" runat="server" />
            <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />
        </div>
    </form>
</body>
</html>

.cs页代码

protected void Page_Load(object sender, EventArgs e)
    {
        hdDate.Value = Convert.ToDateTime(DateTime.Now.AddDays(2)).ToString("yyyy-MM-dd");
    }

日期文本框填充值的屏幕截图。

在编辑模式下,我们使用java脚本设置date的值

相关问题