1

我有一个对话框(模态),我将在其中注册一个(或多个)联系人。

联系人进入网格视图,可以在其中对其进行编辑或删除。

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

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

4

1 回答 1

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

完毕:

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

2-还使用我的视图状态将我的数据保存在数据库中。

于 2011-03-29T12:42:00.893 回答