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

Last Reply 11 months ago By itsme

Posted 11 months 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)


You are viewing reply posted by: itsme 11 months ago.
Posted 11 months 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();