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

Last Reply 9 days ago By itsme

Posted 10 days 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.

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

 

protected void btnEdit_Click(object sender, EventArgs e)
{
    try
    {
        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.ClearSelection();
        Skill.Items.FindByText(skill).Selected = true;
        string quali = (grow.FindControl("lbldegree") as Label).Text;
        Degree.ClearSelection();
        Degree.Items.FindByText(quali).Selected = true;
        string exper = (grow.FindControl("lblexp") as Label).Text;
        exp.ClearSelection();
        exp.Items.FindByText(exper).Selected = true;
        string City = (grow.FindControl("lblcity") as Label).Text;
        city.ClearSelection();
        city.Items.FindByText(City).Selected = true;
        string age = (grow.FindControl("lblage") as Label).Text;
        Age.ClearSelection();
        Age.Items.FindByText(age).Selected = true;
        btnUpdate.Visible = true;
    }
    catch (Exception ex)
    {
        //Response.Write(ex);
    }
}

 

You are viewing reply posted by: itsme 9 days ago.
Posted 9 days ago

I found the answer

here is the working code.

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

 

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