I have one listBox named lstKosnicka and one ADD button named btnDodadi.
protected void btnDodadi_Click(object sender, EventArgs e)
{
DodadiVoKosnicka kosnicka = new DodadiVoKosnicka();
ListItem stavka = new ListItem();
List<ListItem> lista = new List<ListItem>();
stavka = kosnicka.novaStavka(lstPredlog.SelectedItem.Text);
lstKosnicka.DataSource = Session["kosnicka"] as List<ListItem>;
lstKosnicka.Items.Add(stavka);
lstKosnicka.DataBind();
Session["kosnicka"] = lstKosnicka;
lstPredlog.SelectedIndex = -1;
}
There is one more webForm with other listbox named lstKosnickaNajava, and I want to fill this list wtih the same items as lstKosnicka using Session[“kosnicka”], but something is wrong. here is Najava.aspx code:
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie kolace = Request.Cookies["korisnik"];
if (kolace != null)
{
lblNajavenKorisnik.Text = "Најавен коринсик " + kolace["KorisnickoIme"];
}
else
{
lblNajavenKorisnik.Text = "Нема најавени корисници";
}
if (!IsPostBack)
{
lstKosnickaNajava.DataSource = Session["kosnicka"] as List<ListItem>;
lstKosnickaNajava.DataBind();
}
}
but when I go from the first page to Najava.aspx the lstKosnickaNajava is empty.
Maybe you should try in btnDodadi_Click()
this code
if you add only text the list item can be string.
I forget to ask maybe you do this in PAge_Load method??