我想根据从 wcf 服务中检索到的数据绑定我的 gridview。但它只显示 gridview 中的最后一行数据,而不是全部显示。
这是我的 WCF:
try
{
DSCustomer dscat = new DSCustomer();
//input is EmpUserID
cmd.Parameters.AddWithValue("@myuser", id);
cmd.CommandText = "mystoredproc";
List<DSCustomer> lst = new List<DSCustomer>();
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;
}
这是 DScustomer
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; }
}
还有我的 default.aspx:
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<Customer> { cust };
GridView1.DataSource=list;
GridView1.DataBind();
}