Click here to Skip to main content
16,010,470 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm getting the error input string was not in correct format

What I have tried:

try
{
    if (ViewState["dtAck"] != null)
        dtAck = ViewState["dtAck"] as DataTable;

    if (dtAck == null)
        dtAck = AddPanchayats();
    string strFile = string.Empty;
    if (dtAck.Rows.Count > 0)
    {
        //Saving the data
        DataSet dataSetPanchayats = new DataSet();
        dataSetPanchayats.Tables.Add(dtAck);
        string fName = string.Empty;

        foreach (GridViewRow gvr in gvhouseholddetials.Rows)
        {
            TextBox i = (TextBox)gvr.FindControl("txtNOOFCARDSDISTRIBUTED");
            CheckBox checkBox = (CheckBox)gvr.FindControl("checkBox");
            int totalJC = Convert.ToInt32(gvhouseholddetials.Rows[gvr.RowIndex].Cells[4].Text.Trim());
            if (Convert.ToInt32(i.Text) > totalJC && checkBox.Checked)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Please enter proper value of Total no of cards distributed');", true);
                //gvhouseholddetials.Rows[gvr.RowIndex].Focus();
                TextBox txtNOOFCARDSDISTRIBUTED = gvhouseholddetials.Rows[gvr.RowIndex].FindControl("txtNOOFCARDSDISTRIBUTED") as TextBox;
                txtNOOFCARDSDISTRIBUTED.Focus();
                txtNOOFCARDSDISTRIBUTED.Enabled = true;
                checkBox.Checked = false;
                return;
            }

            TextBox d = (TextBox)gvr.FindControl("txtD");
            string txtdate = Convert.ToString(d.Text);

            if (txtdate == "")
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Please select distributed date');", true);
                gvhouseholddetials.Rows[gvr.RowIndex].Focus();
                gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Focus();
                gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Enabled = true;

                TextBox txtTD = gvhouseholddetials.Rows[gvr.RowIndex].FindControl("txtD") as TextBox;
                txtTD.Enabled = true;
                checkBox.Checked = false;
                return;
            }
            if (txtdate != "" && checkBox.Checked)
            {
                DateTime myDate = DateTime.ParseExact(txtdate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                DateTime startDate = DateTime.ParseExact("01/01/2017", "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                if (myDate > DateTime.Today || myDate < startDate)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Please enter proper date' );", true);
                    gvhouseholddetials.Rows[gvr.RowIndex].Focus();
                    gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Focus();
                    gvhouseholddetials.Rows[gvr.RowIndex].Cells[5].Enabled = true;

                    TextBox txtTD = gvhouseholddetials.Rows[gvr.RowIndex].FindControl("txtD") as TextBox;

                    txtTD.Enabled = true;
                    checkBox.Checked = false;
                    return;
                }
            }


        }


        string msg = new GenericBO().GetString(new object[] { dataSetPanchayats.GetXml(), objPortalUser.PCCInfoCode, objPortalUser.UserName, null }, "JobCard_Printing.SaveAcknowledgedJobCard_APO");
        if (msg == "SUCCESS")
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Warning", "alert('Data saved successfully');", true);
            ViewState.Remove("dtAck");
            gvhouseholddetials.DataBind();
            ViewState.Remove("bindGrid");
            //btnSubmit.Visible = false;
        }
Posted
Updated 2-Feb-17 19:52pm

1 solution

You are using Convert.Int32 and DateTime.ParseExact methods in your code. These can lead to exceptions. Debug these two method calls and you might find the problem.

You are probably trying to convert a non-number to a number or a date in different format to a date object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900