Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            connString = WebClass.getConnectionStringByName("sqlSConString");
            if (!Page.IsPostBack)
            {
                ddlHang.Items.Clear();
                ListItem li = new ListItem();
                li.Value = "-1";
                li.Text  = "Chọn Hãng";
                ddlHang.Items.Add(li);

                try
                {
                    CommonCode.DataClasses.DataTool dataTool = new CommonCode.DataClasses.DataTool();
                    string        sql       = "SELECT Hang, XuatXu FROM HangXS";
                    SqlDataReader sqlreader = dataTool.execReader(connString, sql, null);
                    if (sqlreader != null && sqlreader.HasRows)
                    {
                        while (sqlreader.Read())
                        {
                            ListItem item = new ListItem();
                            item.Value = sqlreader.GetSqlString(0).ToString(); //ma hang
                            item.Text  = sqlreader.GetSqlString(0).ToString(); //ten hang
                            ddlHang.Items.Add(item);
                        }
                    }
                }
                catch (Exception exc)
                {
                    Response.Write(String.Format("Lỗi: {0}. Chi tiết: {1}", exc.Message, exc.StackTrace));
                }
                finally
                {
                }

                //đưa dữ liệu lên lưới dữ liệu gridview


                BindDataToGridview();
                gHangHoa.HeaderRow.Cells[0].Text = "Mã Sản Phầm";
                gHangHoa.HeaderRow.Cells[1].Text = "Tên Sản Phầm";
                gHangHoa.HeaderRow.Cells[2].Text = "Hãng ";
                gHangHoa.HeaderRow.Cells[3].Text = "Xuất Xứ";
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            conString = WebClass.getConnectionStringByName("sqlSConString");
            //Response.Write("conString: "+conString+"<br />");
            if (!Page.IsPostBack)
            {
                #region Đọc dữ liệu và đưa lên danh sách dropdownlist
                //ddlTheLoai.Items.Clear();
                ListItem item0 = new ListItem();
                item0.Value = "-1";
                item0.Text  = "Chọn thể loại";
                ddlHang.Items.Add(item0);

                try
                {
                    CommonCode.DataClasses.DataTool dataTool = new CommonCode.DataClasses.DataTool();
                    string        sql       = "SELECT Hang, XuatXu FROM HangXS";
                    SqlDataReader sqlreader = dataTool.execReader(conString, sql, null);
                    if (sqlreader != null && sqlreader.HasRows)
                    {
                        while (sqlreader.Read())
                        {
                            ListItem item = new ListItem();
                            item.Value = sqlreader.GetSqlString(0).ToString(); //hang
                            item.Text  = sqlreader.GetSqlString(0).ToString(); //xuat xu
                            ddlHang.Items.Add(item);
                        }
                    }
                }
                catch (Exception exc)
                {
                    Response.Write(String.Format("Lỗi: {0}. Chi tiết: {1}", exc.Message, exc.StackTrace));
                }
                finally
                {
                }
                #endregion
                //đưa dữ liệu lên Datalist
                BindDataToDataList();
            }
        }
Пример #3
0
        string conString; //= @"Data Source = DESKTOP-TSV4T6E\MSSQL2014; Initial Catalog=Sample;User id=log1;Password=1";
        protected void Page_Load(object sender, EventArgs e)
        {
            conString = WebClass.getConnectionStringByName("sqlSConString");
            //Response.Write("conString: "+conString+"<br />");
            if (!Page.IsPostBack)
            {
                #region Đọc dữ liệu và đưa lên danh sách dropdownlist
                //ddlTheLoai.Items.Clear();
                ListItem item0 = new ListItem();
                item0.Value = "-1";
                item0.Text  = "Chọn thể loại";
                ddlTheLoai.Items.Add(item0);
                //Doan ma nay se duoc thay the bang doan ma duoi - tuong duong

                /*SqlConnection sqlcon = new SqlConnection();
                 * SqlCommand sqlcom2 = new SqlCommand();
                 * try
                 * {
                 *  sqlcon.ConnectionString = conString;
                 *  sqlcon.Open();
                 *  if (sqlcon.State == System.Data.ConnectionState.Open)
                 *  {
                 *      sqlcom2.Connection = sqlcon;
                 *      sqlcom2.CommandType = System.Data.CommandType.Text;
                 *      sqlcom2.CommandText = "SELECT maTheLoai, tenTheLoai FROM TheLoai";
                 *      SqlDataReader sqlreader = sqlcom2.ExecuteReader();
                 *
                 *
                 *      if (sqlreader.HasRows)
                 *      {
                 *          while (sqlreader.Read())
                 *          {
                 *              ListItem item = new ListItem();
                 *              item.Value = sqlreader.GetInt32(0).ToString(); //ma the loai
                 *              item.Text = sqlreader.GetSqlString(1).ToString();//ten the loai
                 *              ddlTheLoai.Items.Add(item);
                 *          }
                 *      }
                 *  }
                 * }
                 * catch (Exception exc)
                 * {
                 *  lThongBao.Text = String.Format("Lỗi: {0}. Chi tiết: {1}", exc.Message, exc.StackTrace);
                 * }
                 * finally
                 * {
                 *  sqlcon.Close();
                 *  sqlcom2.Dispose();
                 * }
                 */
                try
                {
                    CommonCode.DataClasses.DataTool dataTool = new CommonCode.DataClasses.DataTool();
                    string        sql       = "SELECT maTheLoai, tenTheLoai FROM TheLoai";
                    SqlDataReader sqlreader = dataTool.execReader(conString, sql, null);
                    if (sqlreader != null && sqlreader.HasRows)
                    {
                        while (sqlreader.Read())
                        {
                            ListItem item = new ListItem();
                            item.Value = sqlreader.GetInt32(0).ToString();     //ma the loai
                            item.Text  = sqlreader.GetSqlString(1).ToString(); //ten the loai
                            ddlTheLoai.Items.Add(item);
                        }
                    }
                }
                catch (Exception exc)
                {
                    Response.Write(String.Format("Lỗi: {0}. Chi tiết: {1}", exc.Message, exc.StackTrace));
                }
                finally
                {
                }
                #endregion
                //đưa dữ liệu lên lưới dữ liệu gridview
                BindDataToGridView(-1);
            }
        }