Set Date in TextBox when TextMode is Date using C# and VB.Net in ASP.Net

Last Reply one year ago By itsme

Posted one year ago

I am trying to set date in textbox control (Type Date) from database after edit button click.

It is fetching date from database but it is not setting date in textbox control.

        <b>Last Date of Apply:</b>
        <asp:TextBox ID="Apply" runat="server" Width="250px" type="Date" Height="32px"></asp:TextBox>


protected void btnEdit_Click(object sender, EventArgs e)
        Button btn = sender as Button;
        GridViewRow grow = btn.NamingContainer as GridViewRow;
        Id.Value = (grow.FindControl("Id") as Label).Text;
        salary.Text = (grow.FindControl("lblsal") as Label).Text;
        email.Text = (grow.FindControl("lblemail") as Label).Text;
        title.Text = (grow.FindControl("lbltitle") as Label).Text;
        cname.Text = (grow.FindControl("lblname") as Label).Text;
        details.Text = (grow.FindControl("lbldetails") as Label).Text;
        loc.Text = (grow.FindControl("lblLocation") as Label).Text;
        Apply.Text = (grow.FindControl("lblapply") as Label).Text;
        string skill = (grow.FindControl("lblskills") as Label).Text;
        Skill.Items.FindByText(skill).Selected = true;
        string quali = (grow.FindControl("lbldegree") as Label).Text;
        Degree.Items.FindByText(quali).Selected = true;
        string exper = (grow.FindControl("lblexp") as Label).Text;
        exp.Items.FindByText(exper).Selected = true;
        string City = (grow.FindControl("lblcity") as Label).Text;
        city.Items.FindByText(City).Selected = true;
        string age = (grow.FindControl("lblage") as Label).Text;
        Age.Items.FindByText(age).Selected = true;
        btnUpdate.Visible = true;
    catch (Exception ex)


Posted one year ago

Hi itsme,

TextBox with TextMode Date only supports the yyyy-MM-dd format.

So you need to set the date format before assigning it to TextBox.

The browsers that do not support TextMode Date will show as 2019-08-13, but on browsers that support it will display accordingly.

Check this example. Now please take its reference and correct your code.


<asp:TextBox runat="server" ID="Apply" TextMode="Date" />



Apply.Text = DateTime.Now.AddDays(5).ToString("yyyy-MM-dd");


 Apply.Text = DateTime.Now.AddDays(5).ToString("yyyy-MM-dd")


Posted one year ago

I found the answer

here is the working code.

    <td><b>Last Date of Apply:</b></td>
    <td><asp:TextBox ID="Apply" runat="server" Width="250px" type="Date"  Height="32px"></asp:TextBox></td>


string conv = (grow.FindControl("lblapply") as Label).Text;
conv = DateTime.Parse(conv).ToString("yyyy-MM-dd");
Apply.Text = conv.ToString();