Reading Data from SQL DataBase Table to generic collection
<p>I wanted to read all data from a table(containg 3 rows) and to add all the data into generic collection.From collection i wana bind to gridview.</p>

<p>The code displayed below works but only last row is displayed 3 times in gridview.Can You help me.Am a beginer</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    List&lt;Student&gt; listid = new List&lt;Student&gt;();
    Student stud = new Student();
    SqlConnection con = new SqlConnection("........");
    string sql = "select * from StudentInfo";
    con.Open();
    SqlCommand cmd = new SqlCommand(sql, con);
    SqlDataReader dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        stud.Studid = Convert.ToInt32(dr["StudId"]);
        stud.StudName = dr["StudName"].ToString();
        stud.StudentDept = dr["StudentDept"].ToString();
        listid.Add(stud);               
    }
    GridView1.DataSource = listid;
    GridView1.DataBind();
}
public class Student
{
    private int studid;
    public int Studid
    {
       get { return studid; }
       set { studid = value; }
    }    
    private string studName;
    public string StudName
    {
       get { return studName; }
       set { studName = value; }
    }
    private string studentDept;
    public string StudentDept
    {
       get { return studentDept; }
       set { studentDept = value; }
    }
</code></pre>

<p>The output is like this:</p>

<p><img src="http://i.stack.imgur.com/T8gf5.png" alt="enter image description here"></p>
