Hi how to populate an dropdownlist from an method declared as an IEnumerable?
Am getting an error: "Cannot implicitly convert type 'void' to 'string'"
on this line ddlUserType.DataValueField = ddlUserType.DataValueField = _UserTypeInfoList.Insert(0, new UserTypeInfo { UserType ="" }); from code behind file
This is the code am using from a class called UserTypeInfo:
public IEnumerable<UserTypeInfo> GetUserType()
{
using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.GetConnection(), "[GetUserType]"))
{
if (reader.HasRows)
{
while (reader.Read())
{
yield return new UserTypeInfo
{
UserTypeId = Convert.ToInt32(reader["UserTypeId"]),
UserType = Convert.ToString(reader["UserType"])
};
}
}
}
And this the codebehind that am using on PageLoad of a asp.x file:
if (!Page.IsPostBack)
{
UserTypeInfo _UserTypeInfo = new UserTypeInfo();
List<UserTypeInfo> _UserTypeInfoList = _UserTypeInfo.GetUserType().ToList<UserTypeInfo>();
ddlUserType.DataValueField = _UserTypeInfoList.Insert(0, new UserTypeInfo { UserType ="" });
}
And Html code:
<asp:Label ID="lblUserType" runat="server" class="label">User Type :</asp:Label>
<asp:DropDownList ID="ddlUserType" runat="server"></asp:DropDownList>
Need help!!