title: How to bind gridview to a wcf service application?
body: <p>I want to bind my gridview based on the retrieved data from wcf service .But it shows only last row data in gridview instead of showing them all.</p>
  
  <p>Here is my  WCF:</p>
  
  <pre><code>try
  {
    DSCustomer dscat = new DSCustomer();
     //input is EmpUserID
     cmd.Parameters.AddWithValue("@myuser", id);
     cmd.CommandText = "mystoredproc";
     List&lt;DSCustomer&gt; lst = new List&lt;DSCustomer&gt;();
     SqlDataReader dr = cmd.ExecuteReader();
  
     while (dr.Read())
     {
        dscat.MyEmpID = Convert.ToInt32(dr["Emp"]);
        dscat.MyEmpName = dr["EmpName"].ToString();
        dscat.MyUnitName = dr["UnitName"].ToString();
        dscat.MyUnitNumber = Convert.ToInt32(dr["Unit"]);
        dscat.MyRole = dr["Role"].ToString();
        dscat.MySurveyStatus = dr["SurveyStatus"].ToString();
  
        //Add all the returns in to the list from back-end
        lst.Add(dscat);
     }
  
     //returns to the list
     return lst;
  }
  </code></pre>
  
  <p>this is DScustomer</p>
  
  <pre><code>public class DSCustomer
      {
          //Created properties based on the count of the data that we want to retrieve
          public int MyEmpID { get; set; }
          public string MyEmpName { get; set; }
          public string MyUnitName { get; set; }
          public int MyUnitNumber { get; set; }
          public string MyRole { get; set; }
          public string MySurveyStatus { get; set; }
  
      }
  </code></pre>
  
  <p>And my default.aspx:</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
     MyServiceClient client = new MyServiceClient();
     Customer cust = new Customer();
  
     cust = client.getCategori(tbEmpID.Text);
  
     var list = new List&lt;Customer&gt; { cust };
     GridView1.DataSource=list;
     GridView1.DataBind();
  }
  </code></pre>