C# 在回发之前在gridview中保留临时信息

C# 在回发之前在gridview中保留临时信息,c#,.net,asp.net,temp-tables,temporary,C#,.net,Asp.net,Temp Tables,Temporary,我有一个对话框(模式),在那里我将注册一个(或多个)联系人 联系人将转到gridview,在那里可以编辑或删除联系人 Gridview中的数据只能在流程结束时保存在数据库中 我怎样才能做到这一点 模式代码 $(function () { $(".ModalBox").dialog({ autoOpen: false, height: 400, resizable: false, draggable: false,

我有一个对话框(模式),在那里我将注册一个(或多个)联系人

联系人将转到gridview,在那里可以编辑或删除联系人

Gridview中的数据只能在流程结束时保存在数据库中

我怎样才能做到这一点

模式代码

$(function () {
    $(".ModalBox").dialog({
        autoOpen: false,
        height: 400,
        resizable: false,
        draggable: false,
        width: 602,
        modal: true,
        open: function (type, data) {
            $(this).parent().appendTo($("form:first"));
        }
    });
});
OBS.:

[Serializable]
        public class TabelaTempContato
        {
            public int IDCliente { get; set; }
            public string Nome { get; set; }
            public string Email { get; set; }
            public string Telefone { get; set; }
            public string Cpf { get; set; }
            public string Rg { get; set; }
            public string Departamento { get; set; }
            public string Cargo { get; set; }
        }

        protected List ListaTabelaTemp
        {
            get
            {
                if (this.ViewState["TabelaTemp"] == null)
                {
                    this.ViewState["TabelaTemp"] = new List();
                }

                return (List)this.ViewState["TabelaTemp"];
            }
        }

        protected void AddItem()
        {
            this.ListaTabelaTemp.Add(new TabelaTempContato());
            this.gvContato.DataSource = this.ListaTabelaTemp;
            this.gvContato.DataBind();
        }

        protected void btnTest_Click(object sender, EventArgs e)
        {
            this.AddItem();
        }
  • 我没有很好的CSharp或html代码示例,因为我不知道如何实现这一点。我所有的代码看起来都很混乱(已经尝试了很多东西)

  • 我的GridView是一个ascx,模态在同一个ascx中

  • 我相信一些临时桌子或类似的东西会有所帮助,但我从来没有做过类似的事情(看起来像购物车软件),我甚至不知道如何查找它

多谢各位。如果你能做一些代码示例,那就太棒了

编辑: 我做了以下代码:

CSharp代码:

[Serializable]
        public class TabelaTempContato
        {
            public int IDCliente { get; set; }
            public string Nome { get; set; }
            public string Email { get; set; }
            public string Telefone { get; set; }
            public string Cpf { get; set; }
            public string Rg { get; set; }
            public string Departamento { get; set; }
            public string Cargo { get; set; }
        }

        protected List ListaTabelaTemp
        {
            get
            {
                if (this.ViewState["TabelaTemp"] == null)
                {
                    this.ViewState["TabelaTemp"] = new List();
                }

                return (List)this.ViewState["TabelaTemp"];
            }
        }

        protected void AddItem()
        {
            this.ListaTabelaTemp.Add(new TabelaTempContato());
            this.gvContato.DataSource = this.ListaTabelaTemp;
            this.gvContato.DataBind();
        }

        protected void btnTest_Click(object sender, EventArgs e)
        {
            this.AddItem();
        }
我创建了一个临时的gridview,但是数据是空的,我尝试从模式中的文本中提取它,但是我无法,我不知道如何将数据从gridview获取到数据库。(我相信这是比较容易的部分,那么我现在没有集中精力)

编辑:我用我的解决方案创建答案


        [Serializable]
        public struct TempContato
        {
            public int IDCliente { get; set; }
            public string Nome { get; set; }
            public string Email { get; set; }
            public string Telefone { get; set; }
            public string Cpf { get; set; }
            public string Rg { get; set; }
            public string Departamento { get; set; }
            public string Cargo { get; set; }
        }

        protected List ListaTabelaTemp
        {
            get
            {
                if (this.ViewState["ListaTempContato"] == null)
                    this.ViewState["ListaTempContato"] = new List();

                return (List)this.ViewState["ListaTempContato"];
            }
        }

        protected void AddItem()
        {
            TempContato tempContato = new TempContato();

            //tempContato.IDCliente = Convert.ToInt32(this.txtEmailContato.Text);
            tempContato.Nome = this.txtNomeContato.Text;
            tempContato.Email = this.txtEmailContato.Text;
            tempContato.Telefone = this.txtTelefoneContato.Text;
            tempContato.Cpf = this.txtCpfContato.Text;
            tempContato.Rg = this.txtRgContato.Text;
            tempContato.Departamento = this.ddlDepartamentoContato.SelectedValue;
            tempContato.Cargo = this.ddlCargoContato.SelectedValue;

            this.ListaTabelaTemp.Add(tempContato);
        }

        protected void AtualizarGrid()
        {
            this.gvContato.DataSource = this.ListaTabelaTemp;
            this.gvContato.DataBind();
        }

        protected void btnTest_Click(object sender, EventArgs e)
        {
            this.AddItem();
            this.AtualizarGrid();
        }
现在我从我的模型中得到了值!现在只需要一些东西(我相信)

1-获取数据库中的数据以首次加载GridView(如果是版本),并加载新的临时数据

2-保存新的临时数据

完成:

1-我在viewstate中加载并使用它加载网格

2-还可以使用我的viewstate在数据库中保存数据

现在我从我的模型中得到了值!现在只需要一些东西(我相信)

1-获取数据库中的数据以首次加载GridView(如果是版本),并加载新的临时数据

2-保存新的临时数据

完成:

1-我在viewstate中加载并使用它加载网格


2-还可以使用我的viewstate将数据保存在数据库中。

我会非常小心地将列表存储在viewstate中。这可能是一个真正的性能杀手-我自己在很多年前就犯了这个错误。如果在页面范围内需要,请将值推送到隐藏表单字段。否则,一个数据库不会花费你太多。谢谢Corey=)我理解在Viwestate中保存数据的问题。但由于目前的项目很难更改,因此我正在用少量的数据进行分页(通过数据库查询),并等待老板让我重新制作项目(该项目从重新制作o.o.开始)。但这是一个非常好的建议,再次感谢=)我会非常小心地将列表存储在ViewState中。它可能是一个真正的性能杀手-我多年前就犯过这个错误。如果在页面范围内需要,请将值推到隐藏表单字段。否则,数据库不会花费太多。谢谢Corey=)我不理解他在保存Viwestate数据方面遇到了问题。但是由于项目目前还处于状态,所以现在很难更改它,所以我正在用少量的数据进行分页(通过数据库查询),并等待老板让我重新制作项目(该项目从被重新制作o.o.之前的预期开始)。但这是一个伟大而真实的建议,再次感谢=)