无法在asp.net C#中检索文本框中的日期

时间:2015-04-10 09:48:59

标签: asp.net c#-4.0

我无法在Asp.net C#

中的TextBox中检索日期

在Aspx文件中

                                                                                                                                           

                            </div>
                        </div>

                        <div class="form-grou">
                            <asp:Label ID="Joining_Date_Label" runat="server" CssClass="col-lg-4 control-label" Text="Joining Date"></asp:Label>

                            <div class="col-lg-8">
                                <asp:TextBox ID="Joining_Date_TextBox" TextMode="Date" runat="server" CssClass="form-control"></asp:TextBox>


                                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="Joining_Date_TextBox" runat="server" ForeColor="Red" Display="Dynamic" SetFocusOnError="true" ErrorMessage="Joining Date Mandatory"></asp:RequiredFieldValidator>
                            </div>

                        </div>

在Aspx.Cs文件中

 string Connection_string = System.Configuration.ConfigurationManager.ConnectionStrings["CMMS_Standard"].ToString();

    byte Employee_Tittle = 0;
    Int16 Created_by_Employee_Id = 0;
    byte Employee_Designation_ID = 0;
    Int16 Employee_Id = 0;
    byte Deparment_id = 0;
    string Id = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["E_Id"] != null)
        {
            string Username = User.Identity.Name;
            Employee_Detail Employee_Detail_Class = new Employee_Detail();
            Employee_Detail_Class.Retrieve_User_Id(ref Connection_string, ref Username, out Created_by_Employee_Id);


            Id = Request.QueryString["E_Id"];
            Employee_Id = Convert.ToInt16(Employees_detail_id_code.retrive_id(Id));

            if (!IsPostBack)
            {
                Load_Designation();

                DataTable dt;


                Employee_Detail_Class.Retrieve_Employee_Details_By_Id(ref Connection_string, ref Employee_Id, out dt);

                if (dt.Rows.Count > 0)
                {
                    byte Employee_Title = Convert.ToByte(dt.Rows[0]["Employee_Title"]);

                    if (Employee_Title == 1)
                    {
                        Employee_Title_DropDownList.SelectedValue = "Mr";
                    }
                    else if (Employee_Title == 2)
                    {
                        Employee_Title_DropDownList.SelectedValue = "Ms";
                    }
                    else
                    {
                        Employee_Title_DropDownList.SelectedValue = "Mrs";
                    }

                    Employee_Name_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Full_Name"]);
                    Address_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Address"]);
                    Father_Name_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Fathers_Name"]);
                    Mother_Name_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Mothers_Name"]);
                    Date_Of_Birth_TextBox.Text = Convert.ToDateTime(dt.Rows[0]["Employee_DOB"]).ToString("dd-MM-yyyy");

                    Contact_No_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Phone_Number"]);
                    Email_Address_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Email_ID"]);
                    Joining_Date_TextBox.Text = Convert.ToDateTime(dt.Rows[0]["Employee_Joining_Date"]).ToString("dd/MM/yyyy");
                    Employee_Designation_DropDownList.Text = Convert.ToString(dt.Rows[0]["Employee_Designation_ID"]);
                    Employee_Salary_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Salary"]);
                    Per_hour_Salary_TextBox.Text = Convert.ToString(dt.Rows[0]["Employee_Per_Hour_Salary"]);
                    bool Gender_Male = Convert.ToBoolean(dt.Rows[0]["Employee_Gender"]);
                    if (Gender_Male == false)
                    {
                        Male_RadioButton.Checked = true;

                    }
                    else
                    {
                        Female_RadioButton.Checked = true;
                    }
                    Shift_In_Time_TextBox.Text = Convert.ToDateTime(dt.Rows[0]["Shift_In_Timing"]).ToString("hh:mm");
                    Shift_Out_Time_TextBox.Text = Convert.ToDateTime(dt.Rows[0]["Shift_Out_Timing"]).ToString("hh:mm");
                    Remark_TextBox.Text = Convert.ToString(dt.Rows[0]["Remark"]);

                }
            }
            if (Employee_Title_DropDownList.Text == "Mr")
            {
                Employee_Tittle = 1;
            }
            else if (Employee_Title_DropDownList.Text == "Ms")
            {
                Employee_Tittle = 2;
            }
            else
            {
                Employee_Tittle = 3;
            }


        }
        else
        {
            Response.Redirect("~/Error.aspx");
        }

在出生日期TextBox我删除TextMode日期然后它的工作,并在加入日期文本框我没有检索日期,我如何检索日期与textmode =日期属性

1 个答案:

答案 0 :(得分:0)

尝试将日期格式更改为yyyy-MM-dd,因为TextMode="Date"仅支持此日期格式。

Convert.ToDateTime(dt.Rows[0]["Employee_Joining_Date"]).ToString("yyyy-MM-dd");