在回发之前在gridview中保存临时信息

时间:2011-03-28 18:29:19

标签: c# .net asp.net temp-tables temporary

我有一个Dialog(模态),我将注册一个(或几个)联系人。

联系人转到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:

  • 我没有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到我的数据库。 (我相信这是更容易的部分,然后我暂时不关注它)

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

1 个答案:

答案 0 :(得分:1)


        [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-保存新临时数据。

DONE:

1- i加载到我的视图状态并使用它加载网格。

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