如何显示用户刚刚在表单中提交的数据? [英] How to display the data a user just submitted in a form?

查看:49
本文介绍了如何显示用户刚刚在表单中提交的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码来填充表单。代码将填充一组文本框,我有另一个代码来填充另一组文本框。当页面加载时,我收到一个错误,输入字符串的格式不正确。我知道问题是具有Table2013的数据库,因为它没有数据。我想用第二组文本框填充当用户返回到表单时用户刚刚输入数据库的数据,以查看输入的内容。怎么办呢?



I have a code in place to populate a form. The code will populate one set of textboxes and I have another code to populate the other set of textboxes. When the page loads I get an error, "Input string was not in a correct format". I know that the issue is the database that has Table2013 because it has no data in it. I want to populate the second set of textboxes with the data the user just entered into the database when the user comes back to the form to see what was entered. How can this be done?

protected void Page_Load(object sender, EventArgs e)
    {
        ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
        this.lblYEAR.Text = DateTime.Today.ToString("yyyy");
        this.TextBoxDATE.Text = DateTime.Today.ToString("dd-MMM-yy");
        this.lblTime.Text = System.DateTime.Now.ToShortTimeString();
        TextBoxFTUG.Focus();

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();
        SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con2.Open();
        SqlConnection con3 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con3.Open();

        TextBoxINST_ID.Text = Session["inst_id"].ToString();
        SqlCommand scmd = new SqlCommand("Select INST_ID, LongName, City, State from TableCo where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
        SqlCommand scmd2 = new SqlCommand("Select INST_ID, FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, FTEYR from Table2012 where INST_ID = '" + TextBoxINST_ID.Text + "'", con2);
        SqlCommand scmd3 = new SqlCommand("Select INST_ID, FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC from Table2013 where INST_ID = '" + TextBoxINST_ID.Text + "'", con3);
        SqlDataReader dr = scmd.ExecuteReader();
        SqlDataReader dr2 = scmd2.ExecuteReader();
        SqlDataReader dr3 = scmd3.ExecuteReader();
        if (dr.Read())
        if (dr2.Read())
        if (dr3.Read())
            {
                lblCity.Text = dr["City"].ToString();
                lblState.Text = dr["State"].ToString();
                lblSchool.Text = dr["LongName"].ToString();
                lblLYear.Text = dr2["FTEYR"].ToString();

                TextBoxLYFTUG.Text = dr2["FT_UNDERGR"].ToString();
                TextBoxLYFTG.Text = dr2["FT_GRAD"].ToString();
                TextBoxLYTHUGDR.Text = dr2["FTE_UNDERG"].ToString();
                TextBoxLYTHGDR.Text = dr2["FTE_GRAD"].ToString();
                TextBoxLYNCCDR.Text = dr2["NON_CREDIT"].ToString();
                TextBoxLYTCNC.Text = dr2["TOTAL_FTE"].ToString();
                TextBoxLYTNFUG.Text = dr2["FCFTUHC"].ToString();
                TextBoxLYTNFG.Text = dr2["FCFTPBHC"].ToString();
                TextBoxLYTNCPUG.Text = dr2["FCPTUHC"].ToString();
                TextBoxLYTNCPG.Text = dr2["FCPTPBHC"].ToString();
                TextBoxLYTNNCC.Text = dr2["NCHC"].ToString();

                TextBoxFTUG.Text = dr3["FT_UNDERGR"].ToString();
                TextBoxFTG.Text = dr3["FT_GRAD"].ToString();
                TextBoxTHUGDR.Text = dr3["FTE_UNDERG"].ToString();
                TextBoxTHGDR.Text = dr3["FTE_GRAD"].ToString();
                TextBoxNCCDR.Text = dr3["NON_CREDIT"].ToString();
                TextBoxTCNC.Text = dr3["TOTAL_FTE"].ToString();
                TextBoxTNFUG.Text = dr3["FCFTUHC"].ToString();
                TextBoxTNFG.Text = dr3["FCFTPBHC"].ToString();
                TextBoxTNCPUG.Text = dr3["FCPTUHC"].ToString();
                TextBoxTNCPG.Text = dr3["FCPTPBHC"].ToString();
                TextBoxTNNCC.Text = dr3["NCHC"].ToString();



            }
        dr.Close();
        con.Close();
        con2.Close();
        dr2.Close();
        con3.Close();
        dr3.Close();
        

        RangeValidatorLYTNFUG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) - Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);
        RangeValidatorLYTNFUG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) + Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);

        RangeValidatorLYTNFG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFG.Text) - Convert.ToInt32(TextBoxLYTNFG.Text) * 20 / 100);
        RangeValidatorLYTNFG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFG.Text) + Convert.ToInt32(TextBoxLYTNFG.Text) * 20 / 100);

        RangeValidatorLYTNCPUG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPUG.Text) - Convert.ToInt32(TextBoxLYTNCPUG.Text) * 20 / 100);
        RangeValidatorLYTNCPUG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPUG.Text) + Convert.ToInt32(TextBoxLYTNCPUG.Text) * 20 / 100);

        RangeValidatorLYTNCPG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPG.Text) - Convert.ToInt32(TextBoxLYTNCPG.Text) * 20 / 100);
        RangeValidatorLYTNCPG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPG.Text) + Convert.ToInt32(TextBoxLYTNCPG.Text) * 20 / 100);

        RangeValidatorLYTNNCC.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNNCC.Text) - Convert.ToInt32(TextBoxLYTNNCC.Text) * 20 / 100);
        RangeValidatorLYTNNCC.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNNCC.Text) + Convert.ToInt32(TextBoxLYTNNCC.Text) * 20 / 100);

    }

推荐答案

问题不是那么难......看看 http://msdn.microsoft.com/en-us/library/75x4ha6s(v = vs.100).aspx [ ^ ]

就你的错误信息而言,它似乎来自尝试将文本转换为整数时没有任何东西..尝试它像这个..

It is not that tough of a problem..Have a look at http://msdn.microsoft.com/en-us/library/75x4ha6s(v=vs.100).aspx[^]
As far as you error message is concerned , it seems to be coming from trying to convert text to integer when there is nothing there.. try it like this..
int result=0;
if(int.TryParse(textBoxid.Text,out result))


这篇关于如何显示用户刚刚在表单中提交的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆