Exemplo n.º 1
0
        protected void Lst_division_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = Lst_division.SelectedRow;

            //lbl_status.Text = row.Cells[1].Text;
            lbl_familia.Text = row.Cells[2].Text;
            id_familia       = Convert.ToInt32(row.Cells[1].Text);

            LstCategorias.DataSource = null;
            LstCategorias.DataBind();

            LstSubCategorias.DataSource = null;
            LstSubCategorias.DataBind();

            carga_categorias(Convert.ToInt32(row.Cells[1].Text));
        }
Exemplo n.º 2
0
        void carga_categorias(int id_familia)
        {
            string sql = "";

            sql = "select ID_Categoria ID, CONCAT('(',Codigo,')',' ', Nombre) Categoria, IIF(activo=1,'SI','NO') Activo from tbl_Categorias where Id_Familia = " + id_familia;

            sql = "select ID_Categoria ID, ";
            sql = sql + "CONCAT('(', Codigo, ')', ' ', Nombre) Categoria, ";
            sql = sql + "IIF(activo = 1, 'SI', 'NO') Activo, ";
            sql = sql + "(select COUNT(1) from tbl_Subcategorias where Id_Categoria = tbl_Categorias.Id_Categoria) SubCategorias, ";
            sql = sql + "(select COUNT(distinct ct.id_categoria) from tbl_Items_web iw ";
            sql = sql + "inner join tbl_Categorias ct on ct.ID_Categoria = iw.Id_Categoria  where iw.publicado_sitio = 1 ";
            sql = sql + "and ct.ID_Categoria = tbl_Categorias.ID_Categoria) Publicadas ";
            sql = sql + "from tbl_Categorias where Id_Familia = " + id_familia;
            using (SqlConnection connection = new SqlConnection(Sserver))
            {
                try
                {
                    connection.Open();
                    //SqlCommand command = new SqlCommand(sql, connection);
                    SqlDataAdapter reader = new SqlDataAdapter(sql, connection);
                    DataSet        dr     = new DataSet();
                    reader.Fill(dr, "tbl_Categorias");
                    LstCategorias.DataSource = dr;
                    LstCategorias.DataBind();

                    connection.Close();
                    connection.Dispose();
                }
                catch (Exception ex)
                {
                    lbl_error.Text = ex.Message;
                    connection.Close();
                    connection.Dispose();
                }
            }
        }