Olá Franklin,
Você precisa persisti estes dados de forma temporária para depois mostrar novamente, seja através de cookie, viewstate, session, input/hidden:
.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication5.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Digite para adicionar itens na lista:
<asp:TextBox runat="server" ID="txtValor" runat="server" />
<br />
<asp:BulletedList ID="lista" runat="server">
</asp:BulletedList>
<br />
<br />
<asp:Button Text="Adicionar" ID="btnAdicionar" OnClick="btnAdicionar_Click" runat="server" />
</div>
</form>
</body>
</html>
c#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication5
{
public partial class WebForm1 : System.Web.UI.Page
{
public List<string> ItensBulletedList
{
get
{
if (Session["ItensBulletedList"] == null)
Session["ItensBulletedList"] = new List<string>();
return (List<string>)Session["ItensBulletedList"];
}
set
{
Session["ItensBulletedList"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ItensBulletedList = new List<string>();
}
}
protected void btnAdicionar_Click(object sender, EventArgs e)
{
var itens = ItensBulletedList;
itens.Add(txtValor.Text);
ItensBulletedList = itens;
CarregarList(itens);
}
private void CarregarList(List<string> itens)
{
lista.DataSource = itens;
lista.DataBind();
}
}
}
Vitor Mendes |
http://www.vitormendes.com.br/
"Ajuda teu semelhante a levantar a sua carga, porém, não a carregá-la." (Pitágoras)
