Click here to Skip to main content
14,773,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list

List<classname> persons=new List<classname>();

in this list I have records for two persons. If I add a new record in that list it shows only the new record, not the existing records.

but in the (!postback) section when I bind the list to the gridview it shows that two existing records, but after adding the new records it shows only the new.

can anyone find where am committing the mistake.

dear again bind list with grid view
abdul samathu 14-Mar-12 1:34am
i did Mr.Tanveer

my code is

am storing the recods in session like


gridPreviousQualifications.DataSource = persons;

and in the add click event,

protected void btnAdd_Click(object sender, EventArgs e)


DataAccess.Entities ceEntities=new DataAccess.Entities();
BO.Peroson.Qualification qualification = new BO.Person.Qualification(0
, txtPreQualification.Text
, txtPreInstitution.Text
, txtPreBoard.Text
, txtPreYear.Text);

Session["Qualifications"] = persons;

gridPreviousQualifications.DataSource = persons;


when you are adding new record to list then check that list has 2 old records. you can save list in view state and fetch list from viewstate and add new record to that and again save in viewstate. after adding check list has 3 records after checking bind this list to grid view. it will show 3 records now. follow this process, you will found your solution. :-)
abdul samathu 14-Mar-12 1:43am
Mr.sarvesh, the problem is while adding a new record, when the control comes to the persons.add(qualification), it shows that the count in the list is 0, but there are two records already in that list

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