title: Populating Dropdownlist from List collection c#/asp.net
body: <p><em><strong>I have a class named memberdetails and memberdb which are part of my class library. I am using asp.net C# with MSSQL as the back end</em></strong></p>
  
  <p>My memberdetails class</p>
  
  <pre><code>     public int MemID
       {
          get { return memID; }      
       }
  
       public string FirstName
      {
          get { return firstName; }
          set { firstName = value; }
      }
  
       public MemberDetails(int memID, string firstName)
          {
          this.memID = memID;
          this.firstName = firstName;
          }
  </code></pre>
  
  <p>memberdb class</p>
  
  <pre><code>public List&lt;MemberDetails&gt; MemberResult(int memid)
      {  
          using (SqlConnection con = new SqlConnection(connectionString))         
          using (SqlCommand cmd = con.CreateCommand())
          {
              List&lt;MemberDetails&gt; memberdetails = new List&lt;MemberDetails&gt;();
              MemberDetails member;
  
              try
              {
                  con.Open();
                  cmd.CommandText = "usp_Member_Result";
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Parameters.AddWithValue("@memgen", memid);
  
                  using (SqlDataReader reader = cmd.ExecuteReader())
                  {
                      while (reader.Read())
                      {
                          member = new MemberDetails((int)reader["memid"],  (string)reader["firstname"]);
                          memberdetails.Add(member);
  
                      }
                      reader.Close();
                      return memberdetails;                          
                   }
              }
              catch (SqlException err)
              {
                  throw new ApplicationException("Data error.", err);
              }
              finally
              {            
                  if (con != null)
                      con.Close();
              }
          }
      }
  </code></pre>
  
  <p><em><strong>After I compile those classes into a DLL and then add it as a reference to my project I am trying to bind my DropDownlist to retrieve those values. In the codebehind page I am getting a value from the gridview putting it into a variable "memgen" sending that to my method and then returning the results. When I debug my application I see the values are returned however they are not binded to the DropDownList.</em></strong> </p>
  
  <p>CodeBehind Page</p>
  
  <pre><code> member.MemberResult(memgen);
     // MemberDetails details = new MemberDetails();
  
      ddlFamilyMembers.DataTextField = "Text";
      ddlFamilyMembers.DataValueField = "Value"; 
    //  ddlFamilyMembers.DataSource = memberdetails; &lt;&lt; "This does not exist in the current context"
      ddlFamilyMembers.DataBind();
  </code></pre>