protected void LinkButton1_Click(object sender, EventArgs e)
        {
            // ViewState["Detalles5"] = GridView5;
            string      Subcat, Subcat2, IdProducto = "";
            GridViewRow tabla = (GridViewRow)(((LinkButton)sender).Parent.Parent);

            IdProducto  = ((Label)tabla.FindControl("Label1")).Text.ToString();
            Label8.Text = IdProducto;
            SqlDataSource20.SelectCommand = "SELECT OEM.ID_OEM, OEM.OEM, Marca.ID_Marca, Marca.Marca FROM OEM INNER JOIN Producto ON OEM.ID_Producto = Producto.ID_Producto INNER JOIN Marca ON OEM.ID_Marca = Marca.ID_Marca WHERE Producto.ID_Producto = " + IdProducto;
            SqlDataSource20.DataBind();
            SqlDataSource21.SelectCommand = "SELECT CodigoProducto.ID_CodigoProducto, CodigoProducto.Codigo, MarcaProd.ID_MaraProd, MarcaProd.MarcaP FROM CodigoProducto INNER JOIN  Producto ON CodigoProducto.ID_Producto = Producto.ID_Producto INNER JOIN MarcaProd ON CodigoProducto.ID_MaraProd = MarcaProd.ID_MaraProd WHERE Producto.ID_Producto = " + IdProducto;
            SqlDataSource21.DataBind();
            SqlDataSource22.SelectCommand = "SELECT AnioProducto.AnioInicio, AnioProducto.AnioFinal, Rubro.ID_Rubro, Rubro.Rubro, Modelo.Modelo, Marca.Marca FROM Modelo INNER JOIN Marca ON Modelo.ID_Marca = Marca.ID_Marca INNER JOIN Rubro ON Modelo.ID_Modelo = Rubro.ID_Modelo INNER JOIN AnioProducto ON Rubro.ID_Rubro = AnioProducto.ID_Rubro  WHERE AnioProducto.ID_Producto = " + IdProducto;
            SqlDataSource22.DataBind();
            TextBox3.Text = ((Label)tabla.FindControl("Label2")).Text.ToString();
            TextBox4.Text = ((Label)tabla.FindControl("Label3")).Text.ToString();
            Subcat        = ((Label)tabla.FindControl("Label7")).Text.ToString();
            string[] separar;
            separar = Subcat.Split(',');
            //for(int i = 0; i < separar.Length; i++)
            //{
            //
            //}

            // separar = Subcat2.Split(',');
            string categoria = separar[1];

            //   Response.Write("<script>alert('"+ categoria +"')</script>");
            DropDownList17.SelectedIndex = DropDownList17.Items.IndexOf(DropDownList17.Items.FindByText(categoria));
            // ddlsample.SelectedIndex =      ddlsample.Items.IndexOf(     ddlsample.Items.FindByText("x"));
            SqlDataSource19.SelectCommand = "SELECT ID_SubCategoria, SubCategoria FROM SubCategoria WHERE SubCategoria like '%" + separar[0] + "%'";
            SqlDataSource19.DataBind();

            Button4_ModalPopupExtender.Show();
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                byte[] imag = FileUpload2.FileBytes;
                //string msj;

                DatosP.EditarProducto(Convert.ToInt32(Label8.Text), TextBox3.Text, TextBox4.Text, imag, Convert.ToInt32(DropDownList18.SelectedValue));

                foreach (GridViewRow row in GridView8.Rows)
                {
                    DatosP.insertarOEM(row.Cells[2].Text, Convert.ToInt32(Label8.Text), Convert.ToInt32(row.Cells[3].Text));
                }

                foreach (GridViewRow row in GridView9.Rows)
                {
                    DatosP.insertarCodigoMarcaPrd(row.Cells[2].Text, Convert.ToInt32(Label8.Text), Convert.ToInt32(row.Cells[3].Text));
                }

                foreach (GridViewRow row in GridView10.Rows)
                {
                    DatosP.insertarAnioProducto(Convert.ToInt32(Label8.Text), Convert.ToInt32(row.Cells[4].Text), row.Cells[5].Text, row.Cells[6].Text);
                }



                Response.Write("<script>alert('Datos actualizados con exitos, actualiza la pagina!')</script>");
                limpirar();
            }
            catch
            {
                Response.Write("<script>alert('Llene los campos correctamente')</script>");
                Button4_ModalPopupExtender.Show();
            }
        }
        protected void GridView10_RowDeleting1(object sender, GridViewDeleteEventArgs e)
        {
            int index = Convert.ToInt32(e.RowIndex);

            tba = (DataTable)ViewState["Detalles11"];
            tba.Rows[index].Delete();
            GridView10.DataSource = tba;
            GridView10.DataBind();
            Button4_ModalPopupExtender.Show();
        }
 protected void DropDownList8_SelectedIndexChanged(object sender, EventArgs e)
 {
     Button4_ModalPopupExtender.Show();
 }
        protected void Btn_AgergarAnioRP(object sender, EventArgs e)
        {
            tba.Columns.Add("Marca");
            tba.Columns.Add("Modelo");
            tba.Columns.Add("Rubro");
            tba.Columns.Add("ID_Rubro");
            tba.Columns.Add("AnioInicio");
            tba.Columns.Add("AnioFinal");
            foreach (GridViewRow drow in GridView7.Rows)
            {
                DataRow dr = tba.NewRow();
                dr["Marca"]      = drow.Cells[0].Text.ToString();
                dr["Modelo"]     = drow.Cells[1].Text.ToString();
                dr["Rubro"]      = drow.Cells[2].Text.ToString();
                dr["ID_Rubro"]   = drow.Cells[3].Text.ToString();
                dr["AnioInicio"] = drow.Cells[4].Text.ToString();
                dr["AnioFinal"]  = drow.Cells[5].Text.ToString();
                tba.Rows.Add(dr);
            }

            if (DropDownList16.SelectedItem.ToString() != "")
            {
                DataRow dr = null;
                if (ViewState["Detalles11"] != null)
                {
                    for (int i = 0; i < 1; i++)
                    {
                        tba = (DataTable)ViewState["Detalles11"];
                        if (tba.Rows.Count > 0)
                        {
                            dr = tba.NewRow();
                            //  dr["ID"] = Label1.Text;
                            dr["Marca"]      = DropDownList7.SelectedItem.ToString();
                            dr["Modelo"]     = DropDownList8.SelectedItem.ToString();
                            dr["Rubro"]      = DropDownList10.SelectedItem.ToString();
                            dr["ID_Rubro"]   = DropDownList10.SelectedValue.ToString();
                            dr["AnioInicio"] = DropDownList15.SelectedItem.ToString();
                            dr["AnioFinal"]  = DropDownList16.SelectedItem.ToString();

                            tba.Rows.Add(dr);
                            GridView10.DataSource = tba;
                            GridView10.DataBind();
                        }
                    }
                }
                else
                {
                    dr = tba.NewRow();
                    // dr["ID"] = Label1.Text;
                    dr["Marca"]      = DropDownList7.SelectedItem.ToString();
                    dr["Modelo"]     = DropDownList8.SelectedItem.ToString();
                    dr["Rubro"]      = DropDownList10.SelectedItem.ToString();
                    dr["ID_Rubro"]   = DropDownList10.SelectedValue.ToString();
                    dr["AnioInicio"] = DropDownList15.SelectedItem.ToString();
                    dr["AnioFinal"]  = DropDownList16.SelectedItem.ToString();

                    tba.Rows.Add(dr);
                    GridView10.DataSource = tba;
                    GridView10.DataBind();
                }
                ViewState["Detalles11"] = tba;



                GridView10.Visible = true;
                GridView7.Visible  = false;
            }
            else
            {
                Response.Write("<script>alert('Ingrese un codigo')</script>");
            }
            DatosP.DeleteAnioProd(Convert.ToInt32(Label8.Text));
            Button4_ModalPopupExtender.Show();
        }
        protected void Btn_AgergarCodigosP(object sender, EventArgs e)
        {
            tb.Columns.Add("ID");
            tb.Columns.Add("Codigo");
            tb.Columns.Add("ID_Marca");
            tb.Columns.Add("Marca_P");
            foreach (GridViewRow drow in GridView6.Rows)
            {
                DataRow dr = tb.NewRow();
                dr["ID"]       = drow.Cells[0].Text.ToString();
                dr["Codigo"]   = drow.Cells[1].Text.ToString();
                dr["ID_Marca"] = drow.Cells[2].Text.ToString();
                dr["Marca_P"]  = drow.Cells[3].Text.ToString();
                tb.Rows.Add(dr);
            }

            if (TextBox2.Text != "")
            {
                DataRow dr = null;
                if (ViewState["Detalles9"] != null)
                {
                    for (int i = 0; i < 1; i++)
                    {
                        tb = (DataTable)ViewState["Detalles9"];
                        if (tb.Rows.Count > 0)
                        {
                            dr = tb.NewRow();
                            //  dr["ID"] = Label1.Text;
                            dr["ID"]       = "-";
                            dr["Codigo"]   = TextBox2.Text;
                            dr["ID_Marca"] = DropDownList2.SelectedValue.ToString();
                            dr["Marca_P"]  = DropDownList2.SelectedItem.ToString();

                            tb.Rows.Add(dr);
                            GridView9.DataSource = tb;
                            GridView9.DataBind();
                        }
                    }
                }
                else
                {
                    dr = tb.NewRow();
                    // dr["ID"] = Label1.Text;
                    dr["ID"]       = "-";
                    dr["Codigo"]   = TextBox2.Text;
                    dr["ID_Marca"] = DropDownList2.SelectedValue.ToString();
                    dr["Marca_P"]  = DropDownList2.SelectedItem.ToString();

                    tb.Rows.Add(dr);
                    GridView9.DataSource = tb;
                    GridView9.DataBind();
                }
                ViewState["Detalles9"] = tb;


                TextBox2.Text     = "";
                GridView9.Visible = true;
                GridView6.Visible = false;
            }
            else
            {
                Response.Write("<script>alert('Ingrese un codigo')</script>");
            }
            DatosP.DeleteCodigoProd(Convert.ToInt32(Label8.Text));
            Button4_ModalPopupExtender.Show();
        }