Click here to Skip to main content
16,012,107 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello all,
i have 3 text box and a submit button . i want to populate a gridview when submit button click without inserting and writing select db.

for 1st value its ok but for second submit its override the prev with new 1.

thanks
Posted
Updated 7-Apr-11 8:09am
Comments
Sandeep Mewara 7-Apr-11 13:20pm    
Typing in ALL CAPS means SHOUTING in the web world. Kindly, edit and update your question lowering the tone.

BTW. is it a repost? Sounds like, I have read it some time back...
Albin Abel 7-Apr-11 14:03pm    
Could you change the caps to normal form, else you may not get an answer
Raj Bose 7-Apr-11 14:10pm    
Sorry guys ,
Albin Abel 7-Apr-11 15:14pm    
if you could show us the code how you are populating the gridview at the first submit then there are more chances identify the exact issue. Wrong guesses may be costlier.
Raj Bose 7-Apr-11 15:20pm    
I took a object name User and 2 property userId,userName
my code
in button click
User user=new User();
user.UserId=TextBox1.Text;
user.UserName=TextBox2.Text;

IList lst=new ArrayList();
lst.add(user);

GridView1.DataSource=lst;
GridView1.DataBind();

1 solution

IList lst=new ArrayList(); 


The above line is why it is replacing your first submit value.

You are recreating the entire list, and then giving it the only value of the new user you submitted.

Make the lst field a class member, then do this:

if( lst == null )
{
   lst = new ArrayList();
}

lst.add(user); 
GridView1.DataSource=lst; 
GridView1.DataBind();
 
Share this answer
 
Comments
Raj Bose 7-Apr-11 16:13pm    
Thanks alot , it works but 1 more issue :)
When i redirect to other page and return back again to same page the whole data vanish .:)
walterhevedeich 7-Apr-11 23:03pm    
you should store your objects in session and later on rebind it on your gridview whenever you redirect to pages.
Raj Bose 8-Apr-11 9:33am    
Thanks walterhevedeich its work :)

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