예제 #1
0
        protected void gvCategorias_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            // Detectando a linha que foi clicada
            int linha = Convert.ToInt32(e.CommandArgument);

            // Recuperando o id do Objeto (lembrando que 2, do Cells[2], é a coluna onde esta o id)
            int idObjeto  = Convert.ToInt32(gridCategorias.Rows[linha].Cells[2].Text);
            var categoria = _controller.GetById(idObjeto);

            // Nome do comando para saber a acao
            string command = e.CommandName;

            // Proximos passos

            // adicionar id na Session

            if (command.Equals("Delete"))
            {
                _controller.Delete(categoria);
                Response.Redirect("Index.aspx");
                // Redirecionando para tela de exclusao
                //Response.Redirect("Excluir.aspx");
            }
            else
            {
                if (command.Equals("Edit"))
                {
                    var categoriaId = categoria.Id;
                    Convert.ToString(categoriaId);
                    // Redirecionando para tela de edicao
                    Response.Redirect("Editar.aspx?Id=" + categoriaId);
                }
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var IdCategoria = Request.QueryString["Id"];
                var Id          = Convert.ToInt32(IdCategoria);

                var objCategoria = _controller.GetById(Id);
                if (objCategoria != null)
                {
                    txtNome.Text = objCategoria.Nome;

                    if (!String.IsNullOrEmpty(objCategoria.Descricao))
                    {
                        txtDescricao.Text = objCategoria.Descricao;
                    }
                    else
                    {
                        txtDescricao.Text = string.Empty;
                    }

                    if (objCategoria.Ativo == 1)
                    {
                        chkAtivo.Checked = true;
                    }
                    else
                    {
                        chkAtivo.Checked = false;
                    }
                }
                else
                {
                    Response.Redirect("Index.aspx");
                }
            }
        }