Hold temporary information in gridview before post-back
I have a Dialog (Modal), where I'll register one (or several) contact.
the contact goes to a gridview, where they may be edited or deleted.
the data in the Gridview, can only be saved in the database at the end of the process.
How can I achieve this?
Modal code
$(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.:
I don't have a good sample of CSharp or html code, 'cuz i don't know how to achieve this. All my code look messy atm (trying a lot of things already)
My GridView is an ascx, and the modal is in the same ascx.
I belive some temporary table, or something like this will help, but i never did something like it (looks like a shop cart software), and i don't even know how look开发者_如何学编程 for it.
Thank you. if you can do some code sample, it will be GREAT.
EDIT: i did this code:
CSharp code:
[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();
}
i create one temporary gridview, but the data is empty, i tried pull it from my text in the modal, but i was not able to, i'm i'm not familiar in how i'll get the data from gridview to my database. (i believe this is the easier part, then i not focused at it in the moment)
EDIT: I create the answer with my solution.
[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();
}
Now i get the values from my modal! Just need a couple of things now (i belive).
1- Get the data in my database to load the GridView for the first time (if it's an edition), and load with the new temp data.
2- Save the new temp data.
DONE:
1- i load in my viewstate and use it to load the grid.
2- also using my viewstate to save my data, in the database.
精彩评论