I am trying to be a good chap and work with objects. So, I am returning a list of Users (with GroupIDs) to the front end from my DataAccess class ...
In the front end I am populating a Gridview with a list of Users (from a separate DataSource. As I go through the Gridview - in certain conditions - I want to be able to retrieve which GroupIDs the User belongs to from the list above.Code:public List<DataObjects.User> getUsers() { List<DataObjects.User> myUserList = new List<DataObjects.User>(); SqlConnection myConnection = new SqlConnection(connectionString); SqlCommand myCommand = myConnection.CreateCommand(); SqlDataReader dr; myCommand.CommandText = "Users_List"; myCommand.CommandTimeout = 120; myCommand.Connection = myConnection; myCommand.CommandType = CommandType.StoredProcedure; myConnection.Open(); dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); if (dr.HasRows) { while (dr.Read()) { DataObjects.User myUser = new DataObjects.User(); myUser.UserID = dr["UserID"].ToString(); myUser.UserName = dr["UserName"].ToString(); myUser.GroupID = dr["GroupID"].ToString(); myUserList.Add(myUser); } } return myUserList; }
How do I access the list in the front end. I have used Lists before but in the front end I have always used them as the DataSource for a control. Now I just want to be able to filter the List and retrieve the filtered data from the list. How do I do this? Thanks for any help.




Reply With Quote