2011-03-28 29 views
1

我有一个对话框(模态),我将在其中注册一个(或多个)联系人。在回发之前在gridview中保存临时信息

联系人进入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代码的一个很好的样本,“因为我不知道该怎么做到这一点。我所有的代码看起来凌乱(atm已经尝试了很多东西)

  • 我的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中获取数据到我的数据库。 (我相信这是更容易的部分,然后我不专注于此刻)

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

+0

我会非常小心地将您的列表存储在ViewState中。它可能是一个真正的表演杀手 - 我多年前犯了这个错误。如果您在Page范围内需要这些值,请将这些值推送到隐藏表单域。否则,数据库不会花费太多。 – 2011-03-29 13:51:04

+0

感谢Corey =)我明白在Viwestate中保存数据的问题。但作为现在的项目,现在很难改变它,所以我用很少量的分页(通过数据库查询),等到我的老板让我重新制作项目(该项目开始于预先存在重拍oO“)。但是,这是一个伟大的和真实的建议,再次感谢=) – 2011-03-30 18:36:29

回答

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 - 我在我的视图状态加载并使用它来加载网格。

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