protected void ButtonAgrOpcion_Click(object sender, EventArgs e) { SqlConnection con; SqlCommand cmd = new SqlCommand(); String Perfil = DropDownPerfil.SelectedValue; String Opcion = DropDownOpcionPag_N1.SelectedValue; int i = GridViewMenu_N0.SelectedIndex; Label Modulo = (Label)GridViewMenu_N0.Rows[i].FindControl("Modulo"); int Posicion = GridViewMenu_N1.Rows.Count + 1; con = new SqlConnection(BopDBModulos.ConnectionString); cmd.Connection = con; con.Open(); try { cmd.CommandText = "INSERT INTO [dbo].[Menu_N1] ([Perfil],[Modulo],[Posicion],[Opcion]) VALUES('" + Perfil.Trim() + "','" + Modulo.Text.Trim() + "'," + Posicion.ToString() + ",'" + Opcion.Trim() + "')"; cmd.ExecuteNonQuery(); GridViewMenu_N1.DataBind(); } catch (SqlException exception) { if (exception.Number == 2601) // Cannot insert duplicate key row in object error { return; } } }
protected void GridViewMenu_N0_SelectedIndexChanged(object sender, EventArgs e) { int i = GridViewMenu_N0.SelectedIndex; Label Modulo = (Label)GridViewMenu_N0.Rows[i].FindControl("Modulo"); ModuloSel.Text = Modulo.Text; OpcionSel.Text = ""; GridViewMenu_N1.SelectedIndex = -1; GridViewMenu_N1.DataBind(); }