Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 每当listbox所选索引发生更改时,将数据库值检索到文本框_C#_Asp.net_Listbox - Fatal编程技术网

C# 每当listbox所选索引发生更改时,将数据库值检索到文本框

C# 每当listbox所选索引发生更改时,将数据库值检索到文本框,c#,asp.net,listbox,C#,Asp.net,Listbox,因此,每当listbox的选定索引发生更改时,我只想查看从数据库到项目中某些文本框的值 我有这些代码,但每当我单击列表框上的某个项目时,没有一个文本框显示数据或任何东西 protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { if (IsPostBack) { try {

因此,每当listbox的选定索引发生更改时,我只想查看从数据库到项目中某些文本框的值

我有这些代码,但每当我单击列表框上的某个项目时,没有一个文本框显示数据或任何东西

                protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            try
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringHRMS"].ConnectionString);
                conn.Open();
                string selectone = "SELECT * FROM Applicant WHERE ApplicationNo = '" + ListBox1.SelectedValue.ToString() + "'";
                SqlCommand cmd = new SqlCommand(selectone, conn);

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    asln.Text = reader["LastName"].ToString();
                    asfn.Text = reader["FirstName"].ToString();
                    asmn.Text = reader["MiddleName"].ToString();
                    ashea.Text = reader["HEA"].ToString();
                    astitle.Text = reader["Title"].ToString();
                    aspos.Text = reader["Position"].ToString();
                    asaddress.Text = reader["Address"].ToString();
                    asbday.Text = reader["Birthday"].ToString();
                    asgender.Text = reader["Gender"].ToString();
                    asage.Text = reader["Age"].ToString();
                    asht.Text = reader["Height"].ToString();
                    aswt.Text = reader["Weight"].ToString();
                    asemail.Text = reader["Email"].ToString();
                    ascontact.Text = reader["ContactNumber"].ToString();


                }

                reader.Close();
                conn.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex);
            }
        }
    }

检查阅读器是否有一些数据?您需要在每一点上自己调试代码,并检查是否有任何奇怪的地方。因为从这里很难说他们到底出了什么问题。还有一件事,别忘了检查表格中的数据