如何解决如何创建链接按钮以从网格视图中删除一行
我试图为每一行实现一个链接按钮,这样我就可以删除我想要的那个。
稍后我将尝试创建一个文本框,我可以在其中添加新行(需要一些帮助)
到目前为止我无法做到这一点,他抛出了一个错误('DataSource 和 DataSourceID 都定义在'GridView1'上。删除一个定义。' 此异常最初是在此调用堆栈中引发的: 【外码】 AlterarVoos.aspx.cs 中的 Exercicio3.AlterarVoos.LoadVoos() AlterarVoos.aspx.cs 中的 Exercicio3.AlterarVoos.Page_Load(object,System.EventArgs) [外部代码)
到目前为止,我已经做到了:
感谢您的帮助
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();
}
}
}
[![在此处输入图像描述][1]][1]
' OnClientClick="return confirm('Tem a certeza?')">Apagar Registo
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。