Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one listbox in one page.

I added 3 items to that and I want display those 3 items in another page of listbox.

Please help me, anybody know how?
Posted
Updated 12-Jan-11 21:31pm
v2
Comments
Hiren solanki 13-Jan-11 1:40am    
Reply to your comment : please share your code what and how you applied so far.
Rupa1 13-Jan-11 1:44am    
Session["ListViewStore"] = lv.Items this line i wrote in first page after List<ListViewDataItem> fetchback = (List<ListViewDataItem>)Session["ListViewStore"];this line i wrote in second page page_load but its giving error if any modification please inform me......thx
Dalek Dave 13-Jan-11 3:31am    
Edited for Grammar and Syntax.

Use the Session to Achieve this like

C#
//Store Items in a Session
        Session["ListViewStore"] = lv.Items;
//Fetch back with required data type in next page and set the fetched source to listbox.
        List<ListViewDataItem> fetchback = (List<ListViewDataItem>)Session["ListViewStore"];
 
Share this answer
 
Comments
Rupa1 13-Jan-11 1:37am    
sir it's not adding in second page please help me
If it's not adding in second page check if session variable is null or not

C#
if (Session["ListViewStore"] != null)



Adding same code mentioned in my comment below.

C#
if (Session["ListViewStore"] != null) 
{ 

System.Web.UI.WebControls.ListItemCollection list = (System.Web.UI.WebControls.ListItemCollection)Session["ListViewStore"]; 

foreach (ListItem item in list)
 { 
ListBox2.Items.Add(item);
 } 
}
 
Share this answer
 
v2
Comments
Hiren solanki 13-Jan-11 1:54am    
That is just a simple comment to my answer, Nothing more then that. put it in comment so that op can be sync.
Rupa1 13-Jan-11 1:55am    
k kept but coming this error Unable to cast object of type 'System.Web.UI.WebControls.ListItemCollection' to type 'System.Collections.Generic.List`1[System.Web.UI.WebControls.ListViewDataItem]'.
Anupama Roy 13-Jan-11 2:05am    
@Hiren-I am sorry ,will take care in future. @1nagaswarupa-Are you using Paging in ListView & want to show same 3 items in second page of same ListView?Your question says like this "i want display that 3 items in another page of listbox" .It's a bit confusing.
Rupa1 13-Jan-11 2:15am    
i ve one listbox in default.aspx it having some items, i want display the same items of listbox in default2.aspx
Anupama Roy 13-Jan-11 3:38am    
It throws exception because the casting is wrong.I worked out a snippet for you.This will work

if (Session["ListViewStore"] != null)
{
System.Web.UI.WebControls.ListItemCollection list = (System.Web.UI.WebControls.ListItemCollection)Session["ListViewStore"];
foreach (ListItem item in list)
{
ListBox2.Items.Add(item);
}
}
Store the listview object in the session not the items as
Session["sListView"]=lv; 

Then you can access the Listview session in the next page
ListView lvList=(ListView)Session["sListView"];

lvList you will get the exact copy of lv Listview in the first page.

Hope this will help you :). I didn't tried the code for a trial.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900