填充的文本框编辑但不会填充新数据,为什么? [英] Populated textboxes edits but will not populate new data, Why?

查看:100
本文介绍了填充的文本框编辑但不会填充新数据,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于填充数据库中数据的Web表单。用户还可以编辑填充的数据并再次保存。为什么新数据不填充文本框。相反旧的数据仍然显示?



这是我的填充代码:

I have a web form that populates data from the database. The user can also edit the populated data and save it again. Why doesn't the new data populate the textboxes. Instead the old data is still showing?

Here is my populated code:

if (!IsPostBack)
        {
            if (TextBoxINST_ID.Text.Trim().Length > 0)
            {
                SqlConnection con44 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
                con44.Open();

                SqlCommand scmd44 = new SqlCommand("Select FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, UnderG12, Postb9, Total123b4b, THCAS, FTE40, HC50, FTE4050 from Table55 where User_ID = '" + TextBoxUser_ID.Text + "'", con44);
                SqlDataReader dr44 = scmd44.ExecuteReader();
                if (dr44.Read())
                {
                    TextBox1.Text = dr44["FT_UNDERGR"].ToString();
                    TextBox2.Text = dr44["FT_GRAD"].ToString();
                    TextBox3.Text = dr44["FTE_UNDERG"].ToString();
                    TextBox4.Text = dr44["FTE_GRAD"].ToString();
                    TextBox4.Text = dr44["NON_CREDIT"].ToString();
                    TextBox5.Text = dr44["TOTAL_FTE"].ToString();
                    TextBox6.Text = dr44["FCFTUHC"].ToString();
                    
                }
                con44.Close();
                dr44.Close();
            }
        }
    }





这是我的保存按钮代码:



Here is my Save Button code:

protected void ButtonSave_Click(object sender, EventArgs e)
    {
        SqlConnection con7 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con7.Open();

        SqlCommand cmd = new SqlCommand("Insert into Table56 (User_ID, FT_UNDERGR, DATE, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, UnderG12, Postb9, Total123b4b, FTEYR, THCAS, FTE40, HC50, FTE4050) values (@INST_ID, @FT_UNDERGR, @DATE, @FT_GRAD, @FTE_UNDERG, @FTE_GRAD, @NON_CREDIT, @TOTAL_FTE, @FCFTUHC, @FCFTPBHC, @FCPTUHC, @FCPTPBHC, @NCHC, @UnderG12, @Postb9, @Total123b4b, @FTEYR, @THCAS, @FTE40, @HC50, @FTE4050);", con7);

        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@User_ID", TextBoxUser_ID.Text);
        cmd.Parameters.AddWithValue("@FT_UNDERGR", TextBox1.Text);
        cmd.Parameters.AddWithValue("@FT_GRAD", TextBox2.Text);
        cmd.Parameters.AddWithValue("@FTE_UNDERG", TextBox3.Text);
        cmd.Parameters.AddWithValue("@FTE_GRAD", TextBoxTHGDR.Text);
        cmd.Parameters.AddWithValue("@NON_CREDIT", TextBox4.Text);
        cmd.Parameters.AddWithValue("@TOTAL_FTE", TextBox5.Text);
        cmd.Parameters.AddWithValue("@FCFTUHC", TextBox6.Text);
        cmd.Parameters.AddWithValue("@FCFTPBHC", TextBoxTNFG.Text);

推荐答案





我想是的这里的问题是if子句检查第一次加载的页面。



(!IsPostBack)



如果填充数据/文本框的代码在页面内部加载事件,尝试将其移动到单独的例程,并在按钮单击处理程序中调用此例程。



不要在填充数据的例程中检查页面回发条件。让此检查以表单加载为止。
Hi,

I guess the problem here is the if clause that checks for page loaded first time or not .

(!IsPostBack)

If the code that populates data/text boxes is inside your page load event , try moving this to a separate routine and call this routine in the button click handler.

Don't check for page post back condition in the routine that populates the data.Let this check be in form load itself.


这篇关于填充的文本框编辑但不会填充新数据,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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