示例#1
0
        private void LoadContentInfo(object categoryId)
        {
            listBox1.Items.Clear();
            string constr = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;

            using (SqlConnection con = new SqlConnection(constr))
            {
                string sql = "select did,dname from ContentInfo where dtid=@pid";
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    cmd.Parameters.AddWithValue("@pid", categoryId);
                    con.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                int      did   = reader.GetInt32(0);
                                string   dname = reader.GetString(1);
                                WenZhang wz    = new WenZhang();
                                wz.WenZhangId     = did;
                                wz.WenZhangBiaoTi = dname;
                                listBox1.Items.Add(wz);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //如果listBox当前选定项不为空
            if (listBox1.SelectedItem != null)
            {
                //int obj =Convert.ToInt32( listBox1.SelectedItem);
                //string msg = GetWenZhangNeiRongById(obj);
                //textBox1.Text = msg;

                WenZhang wz  = (WenZhang)listBox1.SelectedItem;
                int      did = wz.WenZhangId;
                string   msg = GetWenZhangNeiRongById(did);
                textBox1.Text = msg;
            }
        }