如何创建链接按钮以从网格视图中删除一行

问题描述

我试图为每一行实现一个链接按钮,这样我就可以删除我想要的那个。

稍后我将尝试创建一个文本框,我可以在其中添加新行(需要一些帮助)

到目前为止我无法做到这一点,他抛出了一个错误('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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...