im trying to implemment a link button for each row so i can delete the one i want.
Later on i will try to create a text box where i can add new rows (will need some help to)
so far im not able to do it, he throws an error ('Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.' This exception was originally thrown at this call stack: [External Code] Exercicio3.AlterarVoos.LoadVoos() in AlterarVoos.aspx.cs Exercicio3.AlterarVoos.Page_Load(object, System.EventArgs) in AlterarVoos.aspx.cs [External Code)
So far i´ve done this:
Thank you for your help
namespace Exercicio3
{
public partial class AlterarVoos : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadVoos();
}
}
protected void LoadVoos()
{
Class1 dados = new Class1();
List<Flight> Voo = dados.ListarVoos(); // dados lidos da BD
List<Lvoos> nDS = new List<Lvoos>(); //dados a carregar da GV
foreach (Flight flight in Voo)
{
nDS.Add(new Lvoos()
{
FlightNumber = flight.Number,
seatnumber = flight.seatnumber,
Destination = flight.Airport.Designation,
Origem = flight.Airport1.Designation,
CountryDestination = flight.Airport.Country.Designation,
CountryOrigin = flight.Airport1.Country.Designation,
FlightId = flight.FlightId
});
}
GridView1.DataSource = nDS.OrderBy(s => s.FlightId);
this.GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
int VooId = Convert.ToInt32(((LinkButton)sender).CommandArgument);
this.Label1.Text = String.Format("Voo a apagar é o {0}", VooId);
string msg = "";
Class1 dados = new Class1();
if (!dados.ApagarVoos(VooId, ref msg))
Label2.Text = msg;
else
this.Label2.Text = String.Format("Voo {0} apagado", VooId);
LoadVoos();
this.Label1.Text = GridView1.Rows.Count.ToString();
}
}
}
[![enter image description here][1]][1]
' OnClientClick="return confirm('Tem a certeza?')">Apagar Registo